Results 1 to 6 of 6
Thread: Mortgage Calculator
- 09-05-2011, 07:01 PM #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
C:\Users\Alexa baby\Documents\Document1.java:37: class CALCULATEMONTHLYPAYMENT is public, should be declared in a file named CALCULATEMONTHLYPAYMENT.javaJava 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); } }
public class CALCULATEMONTHLYPAYMENT
^
1 error
Tool completed with exit code 1Last edited by Norm; 09-05-2011 at 07:08 PM. Reason: added code tags
- 09-05-2011, 07:07 PM #2
Re: Mortgage Calculator
What don't you understand about the error message?class CALCULATEMONTHLYPAYMENT is public, should be declared in a file named CALCULATEMONTHLYPAYMENT.java
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.
- 09-05-2011, 07:21 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
- 09-05-2011, 07:22 PM #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.
-
- 09-05-2011, 07:37 PM #6
Member
- Join Date
- Sep 2011
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
Mortgage Calculator
By missmara77 in forum New To JavaReplies: 1Last Post: 09-05-2011, 07:16 PM -
mortgage calculator
By scooter24 in forum New To JavaReplies: 3Last Post: 06-26-2011, 02:21 PM -
Mortgage Calculator
By rsmithjr316 in forum New To JavaReplies: 14Last Post: 01-21-2011, 10:53 PM -
mortgage calculator help
By kalibballer in forum New To JavaReplies: 1Last Post: 03-26-2009, 11:35 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks