Solved

# Can some one with more Java exspirience help

Posted on 2006-04-14
305 Views
This is a School assingment that I just cannot get my mind around, as follows

•      Write a Java program without a graphical user interface that calculates and displays the mortgage payment amount given the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage.  In this program, hard code the amount = \$200,000, the term = 30 years, and the interest rate = 5.75%.   You will need to find out how to calculate a mortgage payment given these variables.

what I have so far

public class CompMortgage
{
//Main method

public static void main (String[] args)
{

p = 200000;
double i = 5.75;
y = 30;
h = (i/(12*100));
n = y*12;
t = 0;
double m = p*(h/(1-(1+h)^-n));

//Calculate monthly payment
System.out.println("Calculate mortgage payment");

double monthlyPayment = p*(h/(1-(1+h)^-n));

//results

System.out.printIn("The Monthly Payment Is" + monthlyPayment);
}
}

Any Help would be appriciated
0
Question by:1blkls1

LVL 17

Accepted Solution

Hi 1blkls1,

Homework is not normally encouraged, but I will give you a tip.  Define the data type for the variables.  Just putting p=200000 will do nothing.  You need to define it, is it an int? double? long? float? String?  Object? Integer? I expect an int/double since your final answer seems to be a double.  Second, and finally, your monthlyPayment expression uses ^ -n.  The ^ character probably meaning to the power of, which is not defined as ^ in java, or in any language that I know of but scripts in excel and other programs.  You should use a predifined function in the Math class.  Check out the java documentation for the Math class at the Java 1.5 API docs:
http://java.sun.com/j2se/1.5.0/docs/api/
Search for Math under all classes then look for a function for "power"

Hope this helps,
Joe P
0

Author Comment

Thanks Joe
0

LVL 17

Expert Comment

Did you arrive at a solution?
I would like to see your final code, I might suggest some things to make it cleaner/better.
Joe P
0

Author Comment

No I won't have a chance to compleate it today,I have to go to work but I will post it tommorro morning when I get in.
0

Author Comment

What I came up with Still won't work

public class StaticCompMortgage
{
//Main method

public static void main (String[]args)
{

double p = 200000.00;// principal
double i = 5.75;// annual interest
double m = 360;// lenght in months
double y = 30;//term in years
double j = i/(12*100);

//Calculate monthly payment
System.out.println("Calculate mortgage payment");

double MonthlyPayment = double p*(j/(1-Math.pow(1+j)-1));

//results

System.out.printIn("MonthlyPayment");
}
}
0

LVL 17

Expert Comment

Well.  Printing out your results should be:
System.out.println("Monthly Payment is: " + MonthlyPayment);

Try that, the rest looks okay to me.
Joe P
0

Author Comment

This is what I have so far

public class CompMortgage
{
//Main method

public static void main (String[]args)
{

double p = 200000.00;// principal
double i = 5.75;// annual interest
double m = 360;// lenght in months
double y = 30;//term in years
double j = i/(12*100);//monthly intrest in decimal form

//Calculate monthly payment
System.out.println("Calculate mortgage payment");

double MonthlyPayment =  p *(i/12)/1-Math.pow(1+(i/12)-y);

//results

System.out.println("Monthly Payment is:" + MonthlyPayment);
}
}

I keep getting this error

C:\Documents and Settings\Phoenix\My Documents\JAV\CompMortgage.java:26: pow(double,double) in java.lang.Math cannot be applied to (double)
double MonthlyPayment =  p *(i/12)/1-Math.pow(1+(i/12)-y);
^
1 error

It seems to be pointing to the period , but I can't find anything wrong.

Tool completed with exit code 1
0

LVL 17

Expert Comment

I think what you want is:
double MonthlyPayment =  p *(i/12)/1-Math.pow(1+(i/12),-y);

That works for me.
Joe P
0

Author Comment

The missing comma, Thanks Joe.
0

Author Comment

What works

public class CompMortgage
{
//Main method

public static void main (String[]args)
{

double p = 200000.00;// principal
double i = .0575;// annual interest
int m = 360;// lenght in months
int y = 30;//term in years
double j = i/(12*100);//monthly interest in decimal form

//Calculate monthly payment
System.out.println("Calculate mortgage payment");

double MonthlyPayment =  p *(i/12)/1-Math.pow(1+(i/12),-y);

//results

System.out.println("Monthly Payment is:" + MonthlyPayment);
}
}

The next challenge

Modify the mortgage program from Week 2 list the loan balance and interest paid for each payment over the term of the loan.  The list would scroll off the screen, but use loops to display a partial list, hesitate, and then display more of the list.  Do not use a graphical user interface.  Break calculations into at least three different methods.

I'll be working on this today and tommorro, Joe do you teach or tutor formally.
0

LVL 17

Expert Comment

Me? I'm a student, a Junior in college myself.
I do this in my spare time, work up some qualifications and stuff =)
Joe P
0

## Featured Post

### Suggested Solutions

Logs to delete in Windows VCenter server ? 11 92
wordsWithout 49 64
parentbit challenge 3 37
countHi2 challenge 7 30
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.