Solved

morgage calculator

Posted on 2008-06-21
3
393 Views
Last Modified: 2011-04-14
i need toi 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.

so far i have the following code. i am lost to the next steps i should take to create this...all help will be appreciated
code below

public class wtest
 {

 public static void main (String[] args)
 {
 double principal =2000000.0;
 double rate =5.75;
 double term =30.0;
 double monthlyPayment =0.0;

 rate = rate/1200.0;
 term = term * 12;
 monthlyPayment = principal * rate/ (1.0 - Math.pow(rate+1,-term));
 System.out.println(monthlyPayment);
 }

 }[/color]



public class Wtest {
public static void main (String[] args) {
double principal = 2000000.0; // nice house!
double[] rates = { 5.35, 5.5, 5.75 };
double[] terms = { 7.0, 15.0, 30.0 };
for (int i = 0; i < rates.length; ++i) {


0
Comment
Question by:devweez
3 Comments
 
LVL 3

Accepted Solution

by:
DarrenMcCall earned 500 total points
ID: 21838967
Are you just looking for the rest of the loop?
for (int i = 0; i < rates.length; i++)

{

System.out.print(terms[i] + " year at " + rates[i] + "%:");

monthlyPayment = principal * rates[i]/ (1.0 - Math.pow(rates[i]+1,-terms[i]));

System.out.println(monthlyPayment);

}

Open in new window

0
 
LVL 11

Expert Comment

by:spoxox
ID: 21841263
Seems every Java intro course has this problem.

Your first start (class wtest) will print a correct amount that just needs formatting. (See Java class NumberFormat http://java.sun.com/j2se/1.4.2/docs/api/java/text/NumberFormat.html.)

Your abortive second attempt (class Wtest) has been completed by DarrenMcCall above. DM relied on your data, which needed the adjustments you made in your first attempt: the annual rate needs to be expressed as a monthly rate, etc.

You're almost there: keep going!
0
 

Author Closing Comment

by:devweez
ID: 31470280
thank you...this is what i was looking for....i was also able to understand how the final loop was needed for.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an explanation of a simple data model to help parse a JSON feed
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now