double payment = MortgageUtils.calculateMtgPmt( mortgage.getMtgPv(), mortgage.getMtgNp(), mortgage.getMtgApr()); double mtgPv = mortgage.getMtgPv(); double mtgNp = mortgage.getMtgNp(); mtgNp = (int) mtgNp; double mtgApr = mortgage.getMtgApr(); // declare variables used for amortization table double tableAnswer = 0; int i; int[] paymentNumber; // tracks payment # double totalLoanBal = payment * mtgNp; // define totalLoan balance double totalIntPaid = totalLoanBal - mtgPv;//Total Interest = Ttl payments - principle double[] loanBal = new double[mtgNp]; //declare loanBal array to store the loan balance as it decrements loanBal[0] = totalLoanBal; // set initial loanBal to totalLoanbal // declare the 4 variables for the interest and principle amortization double[] int_Paid = new double[mtgNp]; double[] principle_Paid = new double[mtgNp]; double[] int_Bal = new double[mtgNp]; double[] principle_Bal = new double[mtgNp]; // set some of initial values of above to zero int_Paid[0] = 0; principle_Paid[0] = 0; //set initial interest to totalBal - principle. Set initial principle balance to principle //entered by user int_Bal[0] = totalIntPaid; principle_Bal[0] = mtgPv; paymentNumber[0] = 1; // set up calculations for each variable array value from 0 to termos for (i=1; i>=mtgNp; i++) { paymentNumber[i] = paymentNumber[i] +1; loanBal[i] = loanBal[i-1] - payment; int_Paid[i] = mtgApr * principle_Bal[i-1]; principle_Bal[i] = principle_Bal[i-1] - (payment - int_Paid[i]); principle_Paid[i] = principle_Paid[i-1] + (payment - int_Paid[i]); int_Bal[i] = int_Bal[i-1] - int_Paid[i]; } //loop output while user enters 1 boolean run_amortTable = false; while (!run_amortTable) { System.out.println(); System.out.println(); System.out.println("Would you like to see amortization table for this mortgage?"); System.out.print("Enter 1 for yes or 2 for no: "); tableAnswer = UserInput.readInNumber(); // initialize answer variable //test to see if user wants to see another table if (tableAnswer < 1 || tableAnswer > 2) { System.out.print("You must enter 1 or 2. Please try again. "); tableAnswer = UserInput.readInNumber(); System.out.println(); run_amortTable = true; } else { if (tableAnswer == 1) { //clear the screen and set flag to continue, got this from Cheryl's code for (i=0; i<25; ++i) System.out.println(); //code for clearing console screen found on //http://www.thescripts.com/forum/thread16485.html run_amortTable = false; System.out.println(" Total "); System.out.println("Payment Principal Principal Interest Interest "); System.out.println(" Paid Balance Paid Balance "); System.out.println(); System.out.print("\n\t--------------------------------------------------------------\n"); for (i=1; i<=mtgNp; i++) { System.out.println("paymentNumber[i]\t principle_Paid[i]\tprinciple_Bal[i]\tint_Paid[i]\t int_Bal[i]"); System.out.print("\n\t--------------------------------------------------------------\n"); System.out.println(" Total "); System.out.println("Payment Principal Principal Interest Interest "); System.out.println(" Paid Balance Paid Balance "); System.out.println(); System.out.print("\n\t--------------------------------------------------------------\n"); System.out.println(); System.out.print("Total of all Payments is" + "$" + totalLoanBal + "\n"); } }