Solved

morgage calculator

Posted on 2008-06-21
3
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb wildfly example 2 110
ejb mdb examples 1 38
programming a polycom voip phone 3 84
What browser will run Java? 7 171
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

737 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