Solved

morgage calculator

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
This is about my first experience with programming Arduino.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Introduction to Processes

726 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