Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Norm

Thread: Mortgage Calculator

  1. #1
    missmara77 is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Mortgage Calculator

    Can some please help me with this... i dont know where i went wrong/ error is at the bottom
    Java Code:
    /**************************************
     * Formula to calculate monthly payment
     * ************************************
     *
     *                            Principal + InterestMontly
     * MonthlyPayment = --------------------------------------------
     *                  1 - (1+ InterestMonthly) ^ -NumberOfPayments
     *
     *
     *Principal = The initial amount of the loan
     *InterestYearly = The annual interest rate (from 1 to 100 percent)
     *InterestMonthly = monthly interest in decimal form = interestYealy / (12 * 100)
     *LengthInYears = the length (in years) of the loan
     *NumberOfPayments = number of months over which loan is amortized = L * 12
     *
     *
     *
     *
     *InterestMonthly = InterestYearly / (12.0*100.0)
     *NumberOfPayments = LengthInYears *12
     *MonthlyPayment = (Principal * InterestMonthly) / (1.0 - (Math.pow(1.0 + InterestMonthly, - NumberOfPayments)))
     *
     *
     *
     *
     *Importing Date class
     */
    
    
    
    import java.text.NumberFormat;
    import java.util.Date;
    
    
    //Demonstrates a public Class
    // File name is CalculateMonthlyPayment.java
    public class CalculateMonthlyPayment
    {
      // Calculate the ComputeMonthlyPayment method
      public static void main(String[] args){
        // Initial Conditions
    	//declares variable and array for different laon and defines hard coded values
        double principal = 200000;
        double interestYearly = 0.0535;
        int lengthInYears = 7;
        // principal is the amount of the loan
        // lengthInYears is the term of the loan in years
    
        // print start infomation
        Date todaysDate = new Date();
        System.out.println ("Week 2 Home work YOMARA 1277: SR-mf-0003");
        System.out.println ("Executed on: " + todaysDate);
    
        // calculate monthly payment and display
        for(int i=0;i<3;i++)
        {
        	double monthlyPayment = ComputeMonthlyPayment(principal, interestYearly, lengthInYears);
        	DisplayMonthlyPayment(principal, lengthInYears, interestYearly, monthlyPayment);
        }
    
    
      }
    
      /************************************************
       * Method to Display  Payment
       ******************************************************/
      public static void DisplayMonthlyPayment(double total, int years, double rate, double monthlyPayment)
      {
        // use currency format for current default locale
        NumberFormat nf = NumberFormat.getCurrencyInstance();
        System.out.println ("");
        System.out.println ("For the loan amount " + nf.format(total) + " over " + years +
                " years term at " + (rate * 100) + "% interest rate");
        System.out.println ("Monthly Payment Amount is: " + nf.format(monthlyPayment));
      }
    
      /************************************************
       * Method to calculate and Return the Monthly Payment
       ******************************************************/
      public static double ComputeMonthlyPayment(double principal, double interestYearly, int lengthInYears)
      {
        double interestMonthly = 0;  // Interest paid Each Month
        double numberOfPayments = 0;
    
        interestMonthly =  ComputeMonthlyInterest( interestYearly );
        numberOfPayments = lengthInYears * 12.0;
        //  Apply the method outlined above
        //  Demonstrates using the power function of the Math class
        return (principal * interestMonthly) / (1.0-(Math.pow((1.0 + interestMonthly),-numberOfPayments)));
      }
    
    
      /*****************************************
       * Method to compute the Monthly Interest
       **********************************************/
      public static double ComputeMonthlyInterest( double interestYearly)
      {
        return interestYearly / (12.0);
      }
    
    
    
    }
    C:\Users\Alexa baby\Documents\Document1.java:37: class CALCULATEMONTHLYPAYMENT is public, should be declared in a file named CALCULATEMONTHLYPAYMENT.java
    public class CALCULATEMONTHLYPAYMENT
    ^
    1 error

    Tool completed with exit code 1
    Last edited by Norm; 09-05-2011 at 07:08 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Mortgage Calculator

    class CALCULATEMONTHLYPAYMENT is public, should be declared in a file named CALCULATEMONTHLYPAYMENT.java
    What don't you understand about the error message?
    A public class "should be declared in a file" with the same name as the classname.


    Check your spelling.

    Why is the class name in the error message all caps?
    Last edited by Norm; 09-05-2011 at 07:10 PM.

  3. #3
    missmara77 is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Re: Mortgage Calculator

    Hi Norm,

    I am very very new to java and i just dont know what i did wrong to get this error and even without caps i get the same message C:\Users\Alexa baby\Documents\Document1.java:37: class CalculateMonthlyPayment is public, should be declared in a file named CalculateMonthlyPayment.java
    public class CalculateMonthlyPayment
    ^
    1 error

    Tool completed with exit code 1

    Do you know a fix? If u do please advise, thank u

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Mortgage Calculator

    Check again that the filename and the classname are spelled EXACTLY the same way.

    What is this:
    C:\Users\Alexa baby\Documents\Document1.java:37

    That looks like a filename. Is that the filename of the file containing the class you are trying to compile?
    Change the filename to be the same as the classname.
    Last edited by Norm; 09-05-2011 at 07:24 PM.
    Fubarable likes this.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Mortgage Calculator

    Quote Originally Posted by Norm View Post
    Check again that the filename and the classname are spelled EXACTLY the same way.
    Yep, and as Norm states in his first post, that they are capitalized EXACTLY the same way.

  6. #6
    missmara77 is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Re: Mortgage Calculator

    @Norm, Thats the location where the file was saved to, I RENAMED THE FILE AND CHANGED IT, NOW I DIDNT GET THE ERROR ANYMORE >>> THANKS TO BOTH OF U,

Similar Threads

  1. Mortgage Calculator
    By missmara77 in forum New To Java
    Replies: 1
    Last Post: 09-05-2011, 07:16 PM
  2. mortgage calculator
    By scooter24 in forum New To Java
    Replies: 3
    Last Post: 06-26-2011, 02:21 PM
  3. Mortgage Calculator
    By rsmithjr316 in forum New To Java
    Replies: 14
    Last Post: 01-21-2011, 10:53 PM
  4. mortgage calculator help
    By kalibballer in forum New To Java
    Replies: 1
    Last Post: 03-26-2009, 11:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •