My program compiles but I have created an endless loop...would anyone have any reccomendations. Thanks.
/*
* Mortgagecalculator5.java
*
*
* To calculate and display the mortgage of the hard coded terms
* amount = $200,000, then the term will be 7 years @ 5.35%, 15 years @ 5.5%, or 30 years @ 5.75%
* Each term will be displayed with its monthly payment, loan balance, and interest paid on the
* loan until the each note has the balance of zero
*
*
*/
CODE
import java.text.*;
import java.io.*;
public class MortgageCalculator5{
public static void main(String[] args){
//Declares and builds the variable of the loan amount
int loanAmount = 200000;
double loanBalance = 200000;
double interestPaid = 0;
int loanTerm[] = {84, 180, 360};
double interest[] = {.0535, .0550, .0575};
double monthlyPayment = 0;
DecimalFormat fmt = new DecimalFormat("0.##");
//Starts array loop
for (int i = 0; i < 3; i++) {
//Declares formula
monthlyPayment = (loanAmount*(interest[i]/12)) / (1 - 1 /Math.pow((1 + interest[i]/12), loanTerm[i]));
//Displays loop with first mortgage and interest paid
if (i == 1)
monthlyPayment = (loanAmount*(interest[0]/12)) / (1 - 1 /Math.pow((1 + interest[0]/12), loanTerm[0]));
loanBalance=loanBalance-monthlyPayment;
interestPaid = monthlyPayment * interest[0];
while (loanBalance > 0){
//Displays Mortgage Calculator with the first terms
System.out.println("Mortgage Calculator");
System.out.println("The loan amount is $200,000");
System.out.println("The term of the loan is " + loanTerm[0]);
System.out.println("The monthly payment is $" + fmt.format(monthlyPayment));
System.out.println("The loan balance is: $" + fmt.format(loanBalance));
System.out.println("The interest paid for the loan is $" + fmt.format(interestPaid));
System.out.println();
interestPaid = monthlyPayment * interest[0];}
//Displays loop with second mortgage and interest paid
loanBalance = 200000;
if (i == 2)
while (loanBalance > 0){
//Declares formulas
monthlyPayment = (loanAmount*(interest[1]/12)) / (1 - 1 /Math.pow((1 + interest[1]/12), loanTerm[1]));
loanBalance=loanBalance-monthlyPayment;
interestPaid = monthlyPayment * interest[1];
//Displays Mortgage Calculator with the first terms until balance equals zero
System.out.println("Mortgage Calculator");
System.out.println("The loan amount is $200,000");
System.out.println("The term of the loan is " + loanTerm[1]);
System.out.println("The monthly payment is $" + fmt.format(monthlyPayment));
System.out.println("The loan balance is: $" + fmt.format(loanBalance));
System.out.println("The interest paid for the loan is $" + fmt.format(interestPaid));
System.out.println();}
//Displays loop with third mortgage and interest paid
loanBalance=200000;
if (i == 3)
while (loanBalance > 0){
//Declares formulas
monthlyPayment = (loanAmount*(interest[2]/12)) / (1 - 1 /Math.pow((1 + interest[2]/12), loanTerm[2]));
loanBalance=loanBalance-monthlyPayment;
interestPaid = monthlyPayment * interest[2];
//Displays Mortgage Calculator with the first terms until balance equals zero
System.out.println("Mortgage Calculator");
System.out.println("The loan amount is $200,000");
System.out.println("The term of the loan is " + loanTerm[2]);
System.out.println("The monthly payment is $" + fmt.format(monthlyPayment));
System.out.println("The loan balance is: $" + fmt.format(loanBalance));
System.out.println("The interest paid for the loan is $" + fmt.format(interestPaid));
System.out.println();}
}
}
}