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

    Default Mortgage Calculator

    Hi Can some please help me with this... i dont know where i went wrong/ error is at the bottom/ im using textpad

    /**************************************
    * 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

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

Similar Threads

  1. mortgage calculator
    By scooter24 in forum New To Java
    Replies: 3
    Last Post: 06-26-2011, 02:21 PM
  2. Mortgage Calculator
    By rsmithjr316 in forum New To Java
    Replies: 14
    Last Post: 01-21-2011, 10:53 PM
  3. Mortgage Calculator
    By pablo2002 in forum Java Applets
    Replies: 3
    Last Post: 09-25-2010, 10:34 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
  •