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));
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"
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
Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
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
1blkls1Author Commented:
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);
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
1blkls1Author Commented:
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
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.
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
1blkls1Author Commented:
The missing comma, Thanks Joe.
0
1blkls1Author Commented:
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
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.
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