Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Monthly Mortage Payment Calculator

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Monthly Mortage Payment Calculator

    Hello. I am trying to build a mortgage calculator or program that will do the following:

    calculate the payment amount for 3 mortgage loans:
    * 7 year at 5.35%
    * 15 year at 5.5%
    * 30 year at 5.75%
    ------------------------------------------------------------------
    The princiaple or starting loan balance is 200,000.00 dollars.

    I know that I will be dealing with arrays (or that is how it should be done) but can not understand how to take a numbe from within side of a array and run it into a "for loop" of some kind. For example, I want to make an array for the loan term from above like so: int [] loanterm = {84,180,360}; one way of writing, or another way like so:

    int [] loanterm = new int [3]
    loanterm [0] = 84;
    loanterm [1] = 180;
    loanterm [2] = 360;
    ------------------------------------------------------------------------
    Here is my code so far:

    /**
     * 
     * Write the program in Java (without a graphical user
     * interface) 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%
     
     *Use an array for the different loans. Display the mortgage
     * payment amount for each loan. 
     */
    package mortgagecr2;
     
    import java.io.IOException;
    import java.text.NumberFormat;
     
    public class Mortgagecr2 {
      public static void main(String[] args) {
        double numB = 200000;  //Loan principle for all 3 loan packages
        double numPMT = 0.0; //balance is set to 0 until formula is ran
     
        int [] numY = {84,180,360}; // declared, defined, brokedown years to months
        double [] numR = {0.00448, 0.00458, 0.004792}; //declared, defined, brokedown interest
     
        NumberFormat money = NumberFormat.getCurrencyInstance(); // declare this statment to convert double to money in the println
     
        numPMT = (numB * numR) / (1 - Math.pow(1/ (1 + numR), numY)); //formula to get monthly payment amount
     
          for(int i= 0; i <=numY; i++)  { //this tells the program 0 is less then numY and then to run formula or println
          System.out.println ("Monthly mortgage payment for loan of" +numB + "dollars at" +numY + "month term with a rate of" +numR + "is " + money.format(numPMT)); // shows on screen the monthly payment
     
            if (i%12 == 0) { // this would be used to have the user see 12 println at a time on the console screen
            System.out.println ("(Enter to show the next 12 months payments)");
        try { //dunno found it as part of the IOException bit
         System.in.read(); //this too is art of the IOException to wait for user to hit a key
        } 
         catch (IOException e)	{ //java catches in memory the key pressed
           return; // returns to the program which should be the end.
         } //try
           } //if loop
          } //for loop
      } //main
    } //class
    In the
    System.out.println
    I want to be able to say, "Monthly mortgage payment for loan of 200,000 dollars at 7 year term with a rate of 5.35 is (?) and contiune on with the other two types (15 years and 30 years and also with the intrest rates) by having the user press the enter key. I just do not know how to get or use a for loop correctly with the array and plus the system.out.println.

    I have read and read and read from my book across 4 chapters and been online to read articles from the java site and also look at other codes, but just not making the conntection with arrays and for loops. All the examples I get are always about prime numbers and nothing close to this example to make that connection for me.

    Lastly, the code will not compile and know that since this is pretty much the best I could do.


  2. #2
    Junior Member
    Join Date
    Jul 2011
    Posts
    25
    My Mood
    Fine
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: Monthly Mortage Payment Calculator

    I think you have to do like this
    edited by moderator
    Last edited by copeg; July 18th, 2011 at 10:06 AM. Reason: removed spoonfed answer

Similar Threads

  1. Calculator
    By javapenguin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 22nd, 2010, 09:00 AM
  2. [SOLVED] Calculator help
    By Bradshjo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 1st, 2010, 05:27 PM
  3. Basic program which gets cost, adds tax, gets payment then calculates change.
    By bibboorton in forum What's Wrong With My Code?
    Replies: 6
    Last Post: August 25th, 2010, 11:31 AM