Mortgage Calculator
<p>I need to make my mortgage calculator amortize payments over the course of 30 years. I am new to Java and have been researching and trying different things but am not having any luck. The loan is for $200,000.00, @ 5.75% and is for 30 years. I need to loop it and do a running balance. What I have coming up right now is the loan amount for every month. Is there anyone who can give me some tips and help me with some ideas with this?</p>

<pre><code> /** Mortgage calculator to determine monthly principal,
 * interest, term, and a running balance.
 * 
 *
 */
 //import directive
 import java.text.DecimalFormat;

 //class header
 public class MyProgram 
 {
//start main
public static void main(String args [])
{

//declare and construct variables   
    double P = 200000; //loan amount
    double i = 5.75/100; //annual interest rate
    int N = 360; //term of loan
    double monthlyPayment = (200000 * 0.0575)/(1 - Math.pow( (1 + i), -N )); //monthly payment
    double monthlyRate = 0.0575/12 * 100;
    double monthlyInterest = 12/0.0575; //monthly interest
    double totalInterest = 360 * 1167.15 - 200000.; //total interest for term of loan




    //declares decimal format
    java.text.DecimalFormat df = new java.text.DecimalFormat("#,###,## 0.00");

    //introducing new object MortgageCalculator
    MortgageCalculator calc = new MortgageCalculator(200000, 0.0575, 360);



    double monthlyPayment1 = calc.calculate();


    //information output on console

    System.out.println ("Mortgage Calculator:");
    System.out.println ("Loan amount: $" + df.format (P));
    System.out.println ("Annual interest rate: " + i);      
    System.out.println ("Breakdown of loan, payments, and interest:");      
    System.out.println ("Term of loan in months: "  + N);
    System.out.println (" Monthly interest rate: "  +  monthlyRate + "%");
    System.out.println ("Monthly payment: $" + df.format(monthlyPayment1));
    System.out.println ("Monthly interest: $" + df.format (monthlyInterest));
    System.out.println ("Total interest: $" + df.format (totalInterest));

    double balance = 2000000;
    monthlyPayment = (200000 * 0.0575)/(1 - Math.pow( (1 + i), -N ));

    for(int I=0; I &lt; N; I++)

        System.out.println("Month " + I + ": Balance remaining $" + df.format(balance)); 

    {

    double interestPaid = 2000000 * 0.0575/12;
    double principalPaid = monthlyPayment1 - monthlyInterest;
    balance =balance - principalPaid;





    }
    //end class
    }
}
//end main






 /**
 * This class encapsulates the input data and performs the 
 * mortgage calculation necessary on them.
 * 
 *
 */


 import java.text.DecimalFormat;

 public class MortgageCalculator 
 {
  private double P = 200000;
  private double i = 0.0575;
  private int N = 360; {

  }


 /*** This is the constructor and it collects the data for
   * calculation later.
   * 
   * @param P - principal
   * @param i - annual interest rate in fractional form
   * @param N - number of periods (so 30 years monthly is 30 x 12 = 360)
   */

  public MortgageCalculator( double P, double i, int N)
  {



    this.P = P;
    this.i = i / 12.0;
    this.N = N;  
  }



  /**)
   * This is the formula for calculating amortized payments.
   * 
   * @return payment
   */
  public double calculate(){

  return P * ( i / (1 - Math.pow( (1 + i), -N ) ) );
  }
  } 
</code></pre>
