Solved

morgage calculator

Posted on 2008-06-21
3
392 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

758 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

18 Experts available now in Live!

Get 1:1 Help Now