0

I have to display the mortgage payment amount and then list the loan balance and interest paid for each payment over the term of the loan but my output isn't changing.

```
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class MortgagePmt {
public static void main(String[] args)
{
int term; //Term in years
double principal; //Principal amount
double rate; //Annual interest rate
double interestPaid ;
double principalPaid;
double principalBalance;
String input;
input = JOptionPane.showInputDialog("Enter the Principal Amount: ");
principal = Double.parseDouble(input);
input = JOptionPane.showInputDialog("Enter the rate (%): ");
rate = Double.parseDouble(input);
input = JOptionPane.showInputDialog("Enter the term (years): ");
term = Integer.parseInt(input);
DecimalFormat two = new DecimalFormat("0.00"); //round to two decimal places
double interest_rate = rate/1200; //Monthly interest rate
int yearly_term = term * 12; //Term in months
double monthlypayment = principal * interest_rate / (1.0 - Math.pow(interest_rate+1, -yearly_term));
System.out.println("\n\n\t Mortgage Calculator\n\n" +
"Principle Amount: \t$" + principal +
"\nInterest Rate (%): \t" + rate + "%" +
"\nTerm (Years): \t" + term);
System.out.println("\nThe monthly payment will be: $" + two.format(monthlypayment));
System.out.println("\n\nMonths\t\tMonthly\t\tInterest\tPrincipal\tBalance");
System.out.println("Remaining\tPayment\t\tPayment\t\tPayment\t\tRemaining");
System.out.println("_________ \t_________ \t_________ \t_________ \t_________");
for (int i = 1; i <= 360; i++) {
interestPaid = principal * interest_rate;
principalPaid = monthlypayment - interestPaid;
principalBalance = principal - principalPaid;
System.out.println(yearly_term + "\t\t" + two.format(monthlypayment) + "\t\t$" + two.format(interestPaid) +
"\t\t$" + two.format(principalPaid) +
"\t\t$" + two.format(principalBalance));
yearly_term--;
}
try{
Thread.sleep(2000);
}catch(InterruptedException e){
//do nothing... for now...
}
}
}
```

this is the output

```
Mortgage Calculator
Principle Amount: $200000.0
Interest Rate (%): 2.0%
Term (Years): 30
The monthly payment will be: $739.24
Months Monthly Interest Principal Balance
Remaining Payment Payment Payment Remaining
_________ _________ _________ _________ _________
360 739.24 $333.33 $405.91 $199594.09
359 739.24 $333.33 $405.91 $199594.09
358 739.24 $333.33 $405.91 $199594.09
357 739.24 $333.33 $405.91 $199594.09
356 739.24 $333.33 $405.91 $199594.09
355 739.24 $333.33 $405.91 $199594.09
etc.
```