Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: investment interest display problem

1. ## 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,

2. ## Re: investment interest display problem

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

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

3. ## 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?