java mortgage calcuator using array for 3 different loan

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phjones
    New Member
    • Dec 2006
    • 4

    java mortgage calcuator using array for 3 different loan

    Need help programming mortagage calculator for 3 different loans 7 year, 15 year and 30 year. using java array I am a beginner with Java, This is what I have so far. Need to know if I am off the path,

    import java.math.*;//*loan calculator
    import java.text.*;//*formats numbers
    public class 3 Mortgage loans {


    // declare class variable array
    int[] mortgage calculator

    //construct the array
    mortgage calculator = new int[17];

    Code:
    [CODE]double loan = 200000
    			double term1 =360//*360 month for 30 year mortgage
    			double interRate1 = 0.0575; //*5.75% 5.75/100interest rate 30year mortgage
     			double monthlyRate1 = (interestRate1/12)
    			double term2 = 84//*7year mortgage loan
    			double interestRate2 = 0.0535;//*5.35 5.35/100 interest rate 7 year mortgage
    			double monthlyRate2 = (interestRate2/12);//*rate calculation on 7 year mortgage loan
    			double term3 = 180
    // 15 year mortgage
    double interestRate3 = 0.0550;//*5.5 5.5/100 interest rate on 15 year mortgage
    double monthlyRate3 = (interestRate3/12);//* monthlyRate for 15 year mortgage

    //Discount factr calculator for the three loans
    double discountFactor1 = (Math.pow ((1 + monthlyRate1),
    term1)-1/(monthlyRate1 * Math.pow((1 + monthlyRate1),t erm1));

    double discountFactor2 = (Math.pow((1 + monthlyRate2),t erm2)-1/
    (monthlyRate2* Math.pow((1 + monthlyRate2),t erm2));

    double discountFactor3 = (Math.pow((1 + monthlyRate3), term3) - 1)/
    (monthlyRate3 * Math.pow((1 + monthlyRate3), term3));

    double payment1 = loan/discountFactor1 ; //*Rate Calcualtion for 30 yearn mortgage
    double payment2 = loan/discountFactor2 ; //*Rate Calculaion for 7 year morgage
    double payment3 = loan/discountFactor3 ; //*Rate Clculation for 15 year mortgage
    [/CODE]
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by phjones
    Need help programming mortagage calculator for 3 different loans 7 year, 15 year and 30 year. using java array I am a beginner with Java, This is what I have so far. Need to know if I am off the path,

    import java.math.*;//*loan calculator
    import java.text.*;//*formats numbers
    public class 3 Mortgage loans {


    // declare class variable array
    int[] mortgage calculator

    //construct the array
    mortgage calculator = new int[17];

    Code:
    [CODE]double loan = 200000
    			double term1 =360//*360 month for 30 year mortgage
    			double interRate1 = 0.0575; //*5.75% 5.75/100interest rate 30year mortgage
    			double monthlyRate1 = (interestRate1/12)
    			double term2 = 84//*7year mortgage loan
    			double interestRate2 = 0.0535;//*5.35 5.35/100 interest rate 7 year mortgage
    			double monthlyRate2 = (interestRate2/12);//*rate calculation on 7 year mortgage loan
    			double term3 = 180
    // 15 year mortgage
    double interestRate3 = 0.0550;//*5.5 5.5/100 interest rate on 15 year mortgage
    double monthlyRate3 = (interestRate3/12);//* monthlyRate for 15 year mortgage

    //Discount factr calculator for the three loans
    double discountFactor1 = (Math.pow ((1 + monthlyRate1),
    term1)-1/(monthlyRate1 * Math.pow((1 + monthlyRate1),t erm1));

    double discountFactor2 = (Math.pow((1 + monthlyRate2),t erm2)-1/
    (monthlyRate2* Math.pow((1 + monthlyRate2),t erm2));

    double discountFactor3 = (Math.pow((1 + monthlyRate3), term3) - 1)/
    (monthlyRate3 * Math.pow((1 + monthlyRate3), term3));

    double payment1 = loan/discountFactor1 ; //*Rate Calcualtion for 30 yearn mortgage
    double payment2 = loan/discountFactor2 ; //*Rate Calculaion for 7 year morgage
    double payment3 = loan/discountFactor3 ; //*Rate Clculation for 15 year mortgage
    [/CODE]
    use public class MortgageLoans as the class name. The one you have is invalid.
    You should define 3 arrays of type double not one of type int
    You will also need a loop to calculate the monthly repayments amounts.
    Make the above corrections and post the code

    Comment

    • phjones
      New Member
      • Dec 2006
      • 4

      #3
      Unfortunately. This maybe a second posting. I sorry just getting started with this chat area. See new code below:

      /**
      * @(#)3 Mortgage loans.java
      *
      * 3 Mortgage loans application
      *
      * Phyllis J Jones
      * Purpose to write a program in Java without a graphical user interface and have
      it calculate the payment amount for 3 mortgage loans.
      */
      import java.math.*;//*loan calculator
      import java.text.*;//*formats numbers
      public class MortgageLoans {



      // declare class variable array
      double mortgage calculator1[];
      double mortgage calculator2[];
      double mortgage calculator3[];
      //construct the array
      mortgage calculator1 = new double[6];
      mortgage calculator2 = new double[6];
      mortgage calculator3 = new double[6];


      double loan = 200000
      double term1 =360//*360 month for 30 year mortgage
      double interRate1 = 0.0575; //*5.75% 5.75/100interest rate 30year mortgage
      double monthlyRate1 = (interestRate1/12)
      double term2 = 84//*7year mortgage loan
      double interestRate2 = 0.0535;//*5.35 5.35/100 interest rate 7 year mortgage
      double monthlyRate2 = (interestRate2/12);//*rate calculation on 7 year mortgage loan
      double term3 = 180 // 15 year mortgage
      double interestRate3 = 0.0550;//*5.5 5.5/100 interest rate on 15 year mortgage
      double monthlyRate3 = (interestRate3/12);//* monthlyRate for 15 year mortgage

      //Discount factr calculator for the three loans
      double discountFactor1 = (Math.pow ((1 + monthlyRate1),
      term1)-1/(monthlyRate1 * Math.pow((1 + monthlyRate1),t erm1));

      double discountFactor2 = (Math.pow((1 + monthlyRate2),t erm2)-1/
      (monthlyRate2* Math.pow((1 + monthlyRate2),t erm2));

      double discountFactor3 = (Math.pow((1 + monthlyRate3), term3) - 1)/
      (monthlyRate3 * Math.pow((1 + monthlyRate3), term3));

      double payment1 = loan/discountFactor1 ; //*Rate Calcualtion for 30 yearn mortgage
      double payment2 = loan/discountFactor2 ; //*Rate Calculaion for 7 year morgage
      double payment3 = loan/discountFactor3 ; //*Rate Clculation for 15 year mortgage



      //loop While not done
      while(loan > 0)
      {

      java.text.Decim alFormat dfm = new java.text.Decim alFormat(",###. 00");
      System.out.prin tln("Your monthly payment is $" + dfm.format(paym ent)+ "cemts");
      // loop while done
      if(loan>0)
      {
      double payment1 = loan/discountFactor1 ;//*Rate Calculation
      double payment2 = loan/discountFactor2 ;//*Rate Calculation
      double payment3 = loan/duiscountFactor 3;//*Rate Calculation
      }
      else
      payment1 = payment/discountFactor1 ;//Rate Calculation
      payment2 = payment/discountFactor2 ;//Rate Calcuklation
      payment3 = payment/discountfactor3 ;//Rate Calculation
      }
      //Output

      }

      }

      Comment

      Working...