I apologize for introducing yet another topic regarding the Java Mortgage Calculator program, but I am at a complete loss at this time. I have done extensive research into this topic including, but not limited to, reading about a dozen threads on this site. The problem that I am having is in regard to calculating and displaying the amortization schedule.

package LoanPayment; import java.math.*; import java.util.*; import java.text.NumberFormat; /** * * @author MPierce */ public class LoanPayment { /** * @param args the command line arguments */ public static void main(String[] args) { double loanAmount = 200000.00; /*Array for the three different Loan Terms */ double [] loanTerm = new double [3]; loanTerm[0] = 84; loanTerm[1] = 180; loanTerm[2] = 360; /*Array for the three different Annual Interest Rates */ double [] interestRate = new double [3]; interestRate[0] = 0.0535; interestRate[1] = 0.055; interestRate[2] = 0.0575; /*Array for the three different Monthly Interest Rates */ double [] monthlyInterestRate = new double [3]; monthlyInterestRate[0] = (interestRate[0] / 12); monthlyInterestRate[1] = (interestRate[1] / 12); monthlyInterestRate[2] = (interestRate[2] / 12); /*Array for the three different loan payments that will be calculated within the program*/ double [] payment = new double [3]; /*The interest, principal, balance, and new balance variables are going * to be used to determine the monthly payment amounts for principal * paid, interest paid, and the new balance on the mortgage */ double interest; double principal; double balance; double newBalance; /*The term variables are used within the calculation to determine monthly * payment for each loan */ double term1; double term2; double term3; double term4; double term5; /*The NumberFormat method automatically rounds up and converts currency * into US standard form */ NumberFormat currency = NumberFormat.getCurrencyInstance(Locale.US); /*Mortgage formula: L = P[i(1 + i)^n]/[(1 + i)^n - 1] * L = Payment * P = Principal * a = annual interest rate * i = monthly interest rate: (a/100)/12 * n = payment term */ /* In order to save space and give the code a cleaner look, I have * condensed the calculations sections into their respective * arrays. */ /* Array indices [0] * The initial payment calculations are made first with a system output * added to display the monthly payment, interest paid, and payment * toward the principal */ { term1 = (1 + monthlyInterestRate[0]); term2 = Math.pow(term1, loanTerm[0]); term3 = (monthlyInterestRate[0] * term2); term4 = (loanAmount * term3); term5 = (term2 - 1); payment[0] = (term4 / term5); interest = (monthlyInterestRate[0] * loanAmount); principal = (payment[0] - interest); balance = (loanAmount - principal); newBalance = (loanAmount - principal); System.out.println("The montly payment for a $200,000 mortgage "+ "with an interest rate of 5.35% on a 7 year term is "+ currency.format(payment[0])); System.out.println("The interest paid for the first payment "+ "is "+ currency.format(interest) + " and the principal "+ "paid is " + currency.format(principal)); /*This section contains the loop for calculating the interest, * principal, and new balance on the mortgage for each month * for the remainder of the loan's term */ for (int month = 2; month <= loanTerm[0]; month++) {interest = (monthlyInterestRate[0] * newBalance); principal = (payment[0] - interest); newBalance = (newBalance - principal); /*I added blank output lines at the beginning and end of each output * as a means of separating the entries and making it easier for the * user to read */ System.out.println(""); System.out.println("Month #" + month); System.out.println("The payment on principal is "+ currency.format(principal)); System.out.println("Interest paid was: " + currency.format(interest)); System.out.println("The new balance on the loan is: " + currency.format(newBalance)); System.out.println(""); }} /* Array indices [1] * The initial payment calculations are made first with a system output * added to display the monthly payment, interest paid, and payment * toward the principal */ {System.out.println(""); System.out.println(""); System.out.println("----------New Loan----------"); System.out.println(""); System.out.println(""); term1 = (1 + monthlyInterestRate[1]); term2 = Math.pow(term1, loanTerm[1]); term3 = (monthlyInterestRate[1] * term2); term4 = (loanAmount * term3); term5 = (term2 - 1); payment[1] = (term4 / term5); interest = (monthlyInterestRate[1] * loanAmount); principal = (payment[1] - interest); balance = (loanAmount - principal); newBalance = (loanAmount - principal); System.out.println("The montly payment for a $200,000 mortgage "+ "with an interest rate of 5.5% on a 15 year term is "+ currency.format(payment[1])); System.out.println("The interest paid for the first payment "+ "is "+ currency.format(interest) + " and the principal "+ "paid is " + currency.format(principal)); /*This section contains the loop for calculating the interest, * principal, and new balance on the mortgage for each month * for the remainder of the loan's term */ for (int month = 2; month <= loanTerm[1]; month++) {interest = (monthlyInterestRate[1] * newBalance); principal = (payment[1] - interest); newBalance = (newBalance - principal); /*I added blank output lines at the beginning and end of each output * as a means of separating the entries and making it easier for the * user to read */ System.out.println(""); System.out.println("Month #" + month); System.out.println("The payment on principal is "+ currency.format(principal)); System.out.println("Interest paid was: " + currency.format(interest)); System.out.println("The new balance on the loan is: " + currency.format(newBalance)); System.out.println(""); }} /* Array indices [2] * The initial payment calculations are made first with a system output * added to display the monthly payment, interest paid, and payment * toward the principal */ {System.out.println(""); System.out.println(""); System.out.println("----------New Loan----------"); System.out.println(""); System.out.println(""); term1 = (1 + monthlyInterestRate[2]); term2 = Math.pow(term1, loanTerm[2]); term3 = (monthlyInterestRate[2] * term2); term4 = (loanAmount * term3); term5 = (term2 - 1); payment[2] = (term4 / term5); interest = (monthlyInterestRate[2] * loanAmount); principal = (payment[2] - interest); balance = (loanAmount - principal); newBalance = (loanAmount - principal); System.out.println("The montly payment for a $200,000 mortgage "+ "with an interest rate of 5.75% on a 30 year term is "+ currency.format(payment[2])); System.out.println("The interest paid for the first payment "+ "is "+ currency.format(interest) + " and the principal "+ "paid is " + currency.format(principal)); /*This section contains the loop for calculating the interest, * principal, and new balance on the mortgage for each month * for the remainder of the loan's term */ for (int month = 2; month <= loanTerm[2]; month++) {interest = (monthlyInterestRate[2] * newBalance); principal = (payment[2] - interest); newBalance = (newBalance - principal); /*I added blank output lines at the beginning and end of each output * as a means of separating the entries and making it easier for the * user to read */ System.out.println(""); System.out.println("Month #" + month); System.out.println("The payment on principal is "+ currency.format(principal)); System.out.println("Interest paid was: " + currency.format(interest)); System.out.println("The new balance on the loan is: " + currency.format(newBalance)); System.out.println(""); }} } }

Just to be clear the code that I have posted is not the current project that I am working on, but a program that I previously wrote. The current project is borrowing the above code for calculations and adding it to a GUI. The problem that I am having is with this particular portion:

for (int month = 2; month <= loanTerm[2]; month++) {interest = (monthlyInterestRate[2] * newBalance); principal = (payment[2] - interest); newBalance = (newBalance - principal);

For reasons that are beyond my comprehension this code will not work when inserted into the new program. I need to get it to recalculate the interest, principal, and new loan balance, displaying it into the jTextArea each time. I have spent the last 12 hours trying to find a way to make it work to no avail. Any advice or guidance that anyone can offer would be greatly appreciated.

Thank you.