# Monthly Mortage Payment Calculator

• July 15th, 2011, 04:27 AM
lockdown
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:

Code :

```/** * * 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
Code :

`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.
• July 17th, 2011, 11:54 PM
serdar
Re: Monthly Mortage Payment Calculator
I think you have to do like this
Code :

`edited by moderator`