# investment interest display problem

• June 3rd, 2011, 07:36 PM
df75douglas
investment interest display problem
hello first year Java student here, I have an assignment to write a program that asked for an investment amount, and interest rate. then calculates it over 30 years and displays it in a list like this:
//what output should look like:

enter investment amount :
enter amount of interest:

year cd value
1 \$value 1 year interest
2 \$value 2 years interest
.
.
29 \$value 29 years interest
30 \$value 30 years interest

here is the code I have written so far

package assign3;

/**
*
* @author david
*/import java.util.Scanner;

public class assing3 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// get info from the user
Scanner input = new Scanner(System.in);
System.out.print ("Enter investment amount: ");
double investmentAmount = input.nextDouble();
System.out.print("Enter yearly interest amount: ");
double yearlyInterestRate = input.nextDouble();
int years = 30;
double cdGain = investmentAmount * (yearlyInterestRate * .01);
double newInvestmentAmount = cdGain + investmentAmount;
System.out.println("new investment amont is: " + newInvestmentAmount);

//print the interst table
printTotal( investmentAmount, yearlyInterestRate, years, cdGain, newInvestmentAmount);
//compute interst amount for each year.

}

static void printTotal(double investmentAmount, double yearlyInterestRate, int years, double cdGain, double newInvestmentAmount){
printTotalbody(investmentAmount, yearlyInterestRate, years, cdGain, newInvestmentAmount);
}
static void printTotalHeading(double investmentAmount, double yearlyInterestRate, int years, double cdGain, double newInvestmentAmount){
System.out.println("Months: CD Value: ");
System.out.println("---------------------------------");
}
//printing the years and values
static void printTotalbody(double newInvestmentAmount, double yearlyInterestRate, int years, double cdGain, double newInvestmentAmount){
int i = 0;
for ( i=0;i < years; i++)

System.out.println(i+1 +" " + newInvestmentAmount );

}
}

I am stumped on how to get the interest to compound and print in order next to the corresponding year.

any help would be appreciated,
• June 3rd, 2011, 07:39 PM
Norm
Re: investment interest display problem
Quote:

how to get the interest to compound
Do you have an equation for this? Must be one online. try google.

Quote:

print in order next to the corresponding year.
What does the program output now?

Please enclose your code in code tags to preserve formatting. See: BB Code List - Java Forums
• June 3rd, 2011, 10:14 PM
df75douglas
Re: investment interest display problem
currently the output is

enter investment amount: (user input1)
enter yearly interest rate : (user input2)
new investment amount is: user input1 * user input2 * .01
year CD value
-------------------------
1 user input1
2 .
. .
.
29
30

not sure how to get the cd value to keep compiling?