0

So I'm in the final days of being able to turn this in, yes it is a homework assignment, but I've almost got it completely done. In fact I'm only having issues with like the last 8 lines. (at least that's all that is causing an error right now.)

Here is what is happening. I designed a mortgage calculator last week that displayed the Loan Amount, the terms, the interest and then calculated the monthly payment. This week I need to make it figure out the Principle Balance and the Interest Paid each month. This will go off the screen so I tried to use loops. Not sure if I know what I'm doing. Just when I think I got it, I dont.

```
* Service Request: SR-mf-03 Mortgage Payment Calculator
* Purpose: Complete Change Request #1 in Service Request SR-mf-003,
Write the program in Java (without a graphical user interface)
using a loan amount of $200,000 with an interest rate of 5.75% and a 30 year term.
Display the mortgage payment amount and then list the loan balance and interest paid
for each payment over the term of the loan. If the list would scroll off the screen,
use loops to display a partial list, hesitate, and then display more of the list.
Insert comments in the program to document the program.
* Mortgage Payment Formula From http://www.rihomesearch.com/15.php.
P= Principal
I= Interest Rate
L= Length
J= Monthly Interest
N= Number of Month Loan is Amortized
* Monthly payment (M) formula:
M = P * ( J / (1 - (1 + J)** -N))
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.*;
public class MortgagePaymentCalc4
{
/* Calculate mortgage payment. The calculation is based on the fixed input which
* are set by variables PrincipleBalance, MonthlyInterest, and Months.
*/
public static void main(String[] args)
{
// Declare Variables
int Months;
double MonthlyPayment, PrincipleBalance, MonthlyInterest;
// Initialize Variables
PrincipleBalance = 200000; // Mortgage Amount
MonthlyInterest = 5.75 / (12*100); // Monthly Interest
Months = 30 * 12; // Mortgage Length
MonthlyPayment = 0; // Monthly Payment
// Calculate Monthly Payment
MonthlyPayment = PrincipleBalance * (MonthlyInterest / (1 - Math.pow(1/(1+MonthlyInterest), Months)));
// Round Cent Decimal
DecimalFormat RoundtoCents = new DecimalFormat("0.00");
//Output Calculation
System.out.println();
System.out.println("\t\t\tMcBride Financial Services");
System.out.println("\t\t Monthly Mortgage Payment Calculator");
System.out.println();
System.out.println();
System.out.println("\t\t\tPrincipal Mortgage: $"+Math.round(PrincipleBalance)+".");
System.out.println("\t\t\tInterest Rate: "+MonthlyInterest*12*100+"%.");
System.out.println("\t\t\tTerm: "+Months/12+" years");
System.out.println();
System.out.println();
System.out.println("\t\t\tMonthly Payment: $"+RoundtoCents.format(MonthlyPayment)+".");
System.out.println();
}
public void listBal()
{
System.out.println();
System.out.println("Month " + "\t" + "Amount " + "\t\t" + "Interest " + "\t" + "Balance ");
// Declare Variables
int periods = 1, Months;
double Balance, Interest, MonthlyPayment, PrincipleBalance, MonthlyInterest;
while(periods <=Months)
{
int i = 0;
while(i <10)
{
Balance = PrincipleBalance*(1+MonthlyInterest) - MonthlyPayment; //Calculation of Balance
Interest = PrincipleBalance*MonthlyInterest; //Calculation of Interest
//Now print using the round to two decimal places
System.out.println(""+periods +"\t\t"+(Math.round(PrincipleBalance*100.00)/100.00)+"\t\t"+(Math.round(Interest*100.00)/100.00)+"\t\t"+(Math.round(Balance*100.00)/100.00));
PrincipleBalance = Balance; //Set the Principal for next round to the Balance of previous month
periods++;
i++;
}
System.out.println("Press Enter to continue..");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
String str = "";
try
{
str = br.readLine();
}
catch (IOException ioe) { System.out.println(ioe); }
}
}
{
MortgagePaymentCalc4 mc2 = new MortgagePaymentCalc4(25, (double)200000, (double)0.0575);
//Calculate Monthly payment
mc2.CalcMonthlyPayment();
//Show the output
mc2.DisplayMonthlyPayment();
mc2.listPrincipleBalance();
}
}
```

Any help or points in the right direction would be greatly appreciated! Thanks!