• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

Can some one with more Java exspirience help

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
1blkls1
Asked:
1blkls1
  • 6
  • 5
1 Solution
 
BogoJokerCommented:
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
 
1blkls1Author Commented:
Thanks Joe
0
 
BogoJokerCommented:
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
What does it mean to be "Always On"?

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.

 
1blkls1Author Commented:
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);




            //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
 
BogoJokerCommented:
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




            //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
 
BogoJokerCommented:
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




            //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
 
BogoJokerCommented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now