Write a program in Java and have it calculate the payment amount for 3 mortgage loans:

profileTop Rated1
 (Not rated)
 (Not rated)
Chat

Write a program in Java and have it calculate the payment amount for 3 mortgage loans:

- 7 year at 5.35%
- 15 year at 5.5%
- 30 year at 5.75%

I need to use an array for the different loans. What I need displayed is as follows:

7 year at 5.35% (or equivalent)
                                Beginning of       End of Month                        Cumulative
Payment No.            Month Amt          Amount              Interest      Interest

I need it to display 25 lines then stop until user hits the enter key, then display another 25 lines. They should be a total of 360 payments for each loan.

I have the first line of each mortgage loan. This is what I have so far:

import java.io.*;
import java.text.DecimalFormat;

public class mortgagepaymentweek4 {
     public static void main(String[] args) throws IOException {
          int startNum, lineCtr, ctr, numMortgages;

          // initalize the year array. This will be a 3 index array with the
          // values
          // 7, 15, and 30 at indexes 0, 1, and 2 respectively
          int lastNum[] = { 7, 15, 30 };
          int maxLineCtr = 25;
          double initAmt, begYearAmt, endYearAmt, intThisYear, cumInterest;

          // initialize the interest rates in the same manner as the years
          double intRate[] = { 0.0535, 0.055, 0.0575 };
          String nothing;
          BufferedReader dataIn = new BufferedReader(new InputStreamReader(
                    System.in));
          DecimalFormat twoDigits = new DecimalFormat("0.00");

          // grab the number of mortgages we are comparing, in this case 3
          numMortgages = lastNum.length;
          lineCtr = 1;

          // start a for loop in order to loop through our array of mortgages
          for (int arrayIndex = 0; arrayIndex < numMortgages; arrayIndex++) {

               // initialize amount and rates, we need to do this in each iteration
               // of the array loop in order to not use old data where we shouldn't
               initAmt = 200000.00;
               // intRate = .0575;
               begYearAmt = initAmt;
               cumInterest = 0.00;

               // compute the monthly payments using the standard mortgage
               // formula
               double i = intRate[arrayIndex] / 12;
               int n = lastNum[arrayIndex] * 12;
               double monthlyPayment = initAmt
                         * ((i * Math.pow((1 + i), n)) / (Math.pow((1 + i), n) - 1));

               // print monthly payments
               System.out
                         .println("----------------------------------------------------------------------------");
               System.out.println(+ lastNum[arrayIndex]
                         + " years at " + (intRate[arrayIndex] * 100) + "% with $"
                         + twoDigits.format(monthlyPayment)
                         + " monthly payment");
                    } // end for
          // System.out.println("line ctr is " + line Ctr);
          System.out
                    .println("----------------------------------------------------------------------------");
     }// end main

}// end class

 
    • 11 years ago
    Answer
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      2009-09-03_231410_mortgagepayment.zip