**Assignment: Write a program that creates a loan amortization table. The user of the program will supply values for Initial Loan Principal, Annual Percentage Rate and Monthly Payment. The program should print out the appropriate amortization table including the number of Monthly Payments and the Total Interest paid for the life of the loan. The program should allow multiple runs of the table process and should allow the user to compare runs in a tabular format (at least 4 different versions) at the end of the program execution.**

I just have several problems with my code:

1.It goes past the loan principal after it is paid off.

2. It is calculating the interest wrong, but I don't know wheere or how to fix it.

3. The Total Interest gets the last value of the interest instead of adding them up.

Here is the code.

/** * @(#)AmortizationTable.java * * [email protected] Maclin *Homework #1 * */ import java.util.Scanner; import java.lang.Math; public class AmortizationTable { public static void main(String[] args) { //int ctrl; Scanner input = new Scanner(System.in);//Creates Scanner input //Prompt the user for Loan Amount System.out.print("Enter the loan Amount: "); double LoanAmt = input.nextDouble(); //Prompt for Number of Years System.out.print("Enter the number of years for the loan: "); int numOfYears = input.nextInt(); //Prompt for APR System.out.print("Enter Annual Percentage Rate(APR) like 8.25: "); double APR = input.nextDouble(); //Prompt for Monthly Payments System.out.print("Enter your monthly payments: "); double MonthlyPayment = input.nextDouble(); //Create the monthly interest rate(APR is a yearly rate) double Mrate = (APR / 1200); System.out.println("Mrate "+Mrate); //Give Balance the value of the Loan Amount double principal = LoanAmt; double TotInterest = 0;//Creates the total interest double principalPay;//The principal loan that changes double interest;//The interest of the loan //The header display System.out.println("Payment #\tPrincipal \t Payment \tAPR \tMR \tInterest Payment \tPrincipal Payment"); int i;//a counter for the loop for(i = 0; i <= numOfYears * 12; i++) { interest = (int) (Mrate * principal * 100) / 100; principalPay = (int) ((MonthlyPayment - interest) * 100) / 100; principal = (int) ((principal - principalPay) * 100) / 100; TotInterest += interest; System.out.println(i + "\t\t\t" + principal + "\t\t\t" + MonthlyPayment + "\t" + APR + "\t" + Mrate + "\t\t" +TotInterest + "\t\t" + principalPay); } System.out.println("The total interest over the life of the loan is: "+TotInterest); } }