My algorithm method in another class is
public double getFutureValue(int numberOfYears, int numberOfTimes)
{
return principal * Math.pow((1 + interestRate / numberOfTimes), (numberOfYears * numberOfTimes));
}
my other class, main class, is supposed to display the year and balance. I created a loop so that the year will display as to how many years the user inputs, but the balance for every year is the same. I don't know what is wrong. Help pleaseee.
Here is my method in main with the loop:
public void menu3()
{
System.out.println("If you invested " + f.format(principal) + " in a bank account paying "
+ f.format(interestRate) + " for " + numberOfYears + " years, \ncompounded " + numberOfTimes
+ " times per year, then your balance will be:");
invest.setPrincipal(principal);
invest.setInterestRate(interestRate);
System.out.println("Years \tBalance");
System.out.println("----------------");
for(int year = 1; year <= numberOfYears; year++)
{
System.out.println(year + "\t" + f.format(invest.getFutureValue(numberOfYears, numberOfTimes)));
}
}
It displays (if user inputs numberOfYears to 6 and all other info thats unrelated to my question)
year balance
1 $1647.01
2 $1647.01
3 ""
4 ""
5 ""
6 ""
What should I do so that it compounds the value for each time and not just the one year?