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){
printTotalHeading(investmentAmount, yearlyInterestRate, years, cdGain, newInvestmentAmount);
printTotalbody(investmentAmount, yearlyInterestRate, years, cdGain, newInvestmentAmount);
}
//print the heading
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,