1. Member
Join Date
Sep 2011
Posts
6
Rep Power
0

## 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. ## 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.

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

3. Member
Join Date
Sep 2011
Posts
6
Rep Power
0

## 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. ## 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.

5. ## Re: Mortgage Calculator

Originally Posted by Norm
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. Member
Join Date
Sep 2011
Posts
6
Rep Power
0

## 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,

#### Posting Permissions

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