Solved

morgage calculator

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 38
Change the background and font colors in Notepad++ 5 84
even odd program using while loop 3 40
eclipse console opening separately 2 19
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

770 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