# Incorrect results

• January 28th, 2012, 07:02 PM
kprofgold
Incorrect results
Hi I was hoping to get some help with my code. I think the formulas may be wrong and I just cant figure it out. My results are incorrect. Here is the assignment with my code. Write the program in Java (without a graphical user interface) and have it calculate the payment amount for 3 mortgage loans:

- 7 year at 5.35%
- 15 year at 5.5%
- 30 year at 5.75%

Use an array for the different loans. Display the mortgage payment amount for each loan and then list the loan balance and interest paid for each payment over the term of the loan. Use loops to prevent lists from scrolling off the screen

public class MortgageCalculator3 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double loanAmount = 200000; //This is the loan amount
double monthlyPayment[] = new double[3];//creates the new variable
monthlyPayment[0] = (loanAmount * 5.35 * (Math.pow((1 + 5.35 / 1200), 84))) / (1200 * (Math.pow((1 + 5.35 / 1200), 84) - 1));//creates the formula for 7 year loan
monthlyPayment[1] = (loanAmount * 5.5 * (Math.pow((1 + 5.5 / 1200), 180))) / (1200 * (Math.pow((1 + 5.5 / 1200), 180) - 1));//creates the formula for 15 year loan
monthlyPayment[2] = (loanAmount * 5.75 * (Math.pow((1 + 5.75 / 1200), 360))) / (1200 * (Math.pow((1 + 5.75 / 1200), 360) - 1));//creates the formula for 30 year loa

double interestRate[] = new double[3];
interestRate[0] = 5.75;
interestRate[1] = 5.5;
interestRate[2] = 5.35;

double loan[] = new double[1];
loan[0] = 200000.00;

System.out.println("MortgageCalculator");
System.out.println("Loan A");
System.out.println("Loan Amount: \$200,000");
System.out.println("Annual Interest: 5.75%");
System.out.println("Loan Length: 30 years");
System.out.println("Monthly Payment: " + monthlyPayment[2]);

double currentLoanAmount;
currentLoanAmount = loanAmount;
for (int i = 1; i <= 360; i++) { //begins the loop process for 360 payments
if (loanAmount > currentLoanAmount) {
currentLoanAmount = 0;
}

double interestPayment = loanAmount * currentLoanAmount;
currentLoanAmount -= (loanAmount - interestPayment);
System.out.println("For payment #" + i + ", The Interest Payment is \$" + (interestPayment));//displays the results of the interest payment
System.out.println("For payment #" + i + ", The Remaining Balance is \$" + (currentLoanAmount));//displays the results of the remaining balance
currentLoanAmount = 0;
}
System.out.println("Loan B");
System.out.println("Loan Amount: \$200,000");
System.out.println("Annual Interest: 5.55%");
System.out.println("Loan Length: 15 years");
System.out.println("Monthly Payment: " + monthlyPayment[1]);

currentLoanAmount = loanAmount;
for (int i = 1; i <= 360; i++) { //begins the loop process for 360 payments
if (loanAmount > currentLoanAmount) {
currentLoanAmount = 0;
}

double interestPayment = loanAmount * currentLoanAmount;
currentLoanAmount -= (loanAmount - interestPayment);
System.out.println("For payment #" + i + ", The Interest Payment is \$" + (interestPayment));//displays the results of the interest payment
System.out.println("For payment #" + i + ", The Remaining Balance is \$" + (currentLoanAmount));//displays the results of the remaining balance
currentLoanAmount = 0;
}
System.out.println("Loan C");
System.out.println("Loan Amount: \$200,000");
System.out.println("Annual Interest: 5.35%");
System.out.println("Loan Length: 7 years");
System.out.println("Monthly Payment: " + monthlyPayment[0]);

currentLoanAmount = loanAmount;
for (int i = 1; i <= 360; i++) { //begins the loop process for 360 payments
if (loanAmount > currentLoanAmount) {
currentLoanAmount = 0;
}
double interestPayment = loanAmount * currentLoanAmount;
currentLoanAmount -= (loanAmount - interestPayment);
System.out.println("For payment #" + i + ", The Interest Payment is \$" + (interestPayment));//displays the results of the interest payment
System.out.println("For payment #" + i + ", The Remaining Balance is \$" + (currentLoanAmount));//displays the results of the remaining balance
currentLoanAmount = 0;
}

}
}
• January 28th, 2012, 07:08 PM
Norm
Re: Incorrect results
Cross posted at: Incorrect formulas