Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## 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;//creates the new variable
monthlyPayment = (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 = (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 = (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;
interestRate = 5.75;
interestRate = 5.5;
interestRate = 5.35;

double loan[] = new double;
loan = 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);

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);

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);

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;
}

}
}  Reply With Quote

3. ## Re: Incorrect results

Cross posted at: Incorrect formulas  Reply With Quote