Solved

# Java Mortgage Calculator

Posted on 2008-10-20

Hello experts, I am in Java class and I am having difficulties with my assignment. I have an assignment that I must create a calculator that can show the monthly payments on a 30 year mortgage. The principals are from $100000 -$200000 and shows the amount of interest between 6%-10% in 0.5% intervals. The output should be in a table format. Here is what our instructor is asking us to perform:

Programming problem 2: Mortgage monthly payment

The monthly payment on mortgage loan of L dollars, at a rate of interest r is given

by

Monthly payment = [ L(r/12)(1 + r/12) 12 n] / [(1 + r/12)12n - 1]

Where N is the number of years of mortgage. Write a program to find the monthly

payment for 30 years, for principals from $100,000 through $200,000(with increments

of $20,000) and interest rates of 6% through 10% (with increments of 0.5%). Print

monthly payment as a whole number (rounded off).

The output must be a neat table, similar to the following (your answers may be slightly

different because of rounding off).

Principal 6% 6.5% 7% 7.5% 8% 8.5% 9% 9.5% 10%

100000 600 632 665 699 733 768 804 840 877

120000 719 758 798 839 880 922 965 1009 1053

140000 & & & & & & & & &

160000 & & & & & & & & &

180000 & & & & & & & & &

200000 & & & & & & & & &

Hint: Use the following idea to compute (1 + r/12)

double temp = 1+r/12;

double temp1 = 1;

for (int i = 1; i<=12*N;i++)

{

temp1 = temp1*temp;

}

The final formula now becomes:

double mp = (L*(r/12)*temp1)/(temp1-1);

Here is what I have so far with my code:

import java.util.*;

class mortgageCalculator;

{

public static void main(String[]args)

{

double temp = 1+r/12;

double temp1 = 1;

double mp = (L*(r/12)*temp1)/(temp1-1);

for (int i = 1; i<=12*30;i++)

{

temp1 = temp1*temp;

}

for(temp1=.06;temp1<=.10;temp1++) // Is this the loop for the interest rate??

{

System.out.println("Monthly Payments" + mp);

}

for( int principal=100000;principal<=200000;principal++) // I am guessing there needs to be a loop to set the principal?

{

}

This table format looks like an array format. We haven't gotten into array's yet and I am pretty confused and unsure how to get started. I don't think this is supposed to be a GUI type of program. Any advice and guidance you could give me would be great. Thank you for your time.