My interest category for the line is "6.5" when it should be "65". The numbers stay same for each year, when they should be updating every year. Also, I can't seem to figure out how to get my new initial balance in the second year to update. By update I mean the new initial balance for the second year should be the ending balance of the first year, and so on.
My second problem is with my return statement calcInterest();
. I am having trouble carrying my result to a different method. Thanks for any and all help!
import java.util.*;
import java.text.*;
public class Interest {
public static void main(String[] args) {
// TODO Auto-generated method stub
printIntro(); // Inform user what program will compute
Scanner console = new Scanner(System.in);
System.out.print("What is the deposit balance ?: ");
double balance = console.nextDouble();
System.out.println(balance);
System.out.print("What is the interest rate ?: ");
double rate = console.nextDouble();
System.out.println(rate);
System.out.print("How many years?: ");
int years = console.nextInt();
System.out.println(years);
printTable(years, balance, rate);
}
public static void printIntro() {
System.out.println("This program will calculate interest on a deposit of your choosing over a specified period.");
}
public static void printTable(int numRows, double balance, double rate) {
System.out.println("Year" + "\t" + "Balance" + "\t" + "\t" + "Interest" + "\t" + "New Balance");
System.out.println("----" + "\t" + "-------" + "\t" + "\t" + "--------" + "\t" + "-----------");
for (int i = 1; i <= numRows; i++) {
printRow(i, balance, rate);
}
}
public static void printRow(int rowNum, double balance, double interest) {
System.out.println(rowNum + "\t" + balance + "\t" + "\t" + interest + "\t" + "\t" + (balance + interest));
balance = (balance + interest);
}
public static double calcInterest(double balance, double rate) {
double interest = balance * (rate / 100);
return interest;
}
}