# Need help please

• December 18th, 2011, 10:18 PM
kprofgold
I have about 4 hours of class time with Java and have an assignment due. I cant figure out how to fix my code. I know Im having issues with my print statements but I just dont understand it. Here is what I have and what is required: Calculate and display the monthly payment amount to fully amortize a \$200,000.00 loan over a 30 year term at 5.75% interest. Please help.

package mortgagecalculator;

public class MortgageCalculator {
public static void main(String[] args) {

}

double annualInterest = 5.75; //This is the annual interest rate
double loanAmount = 200000; //This is the loan amount
double loanLengthInYears = 30; //This is the length of the loan in years

//Formuals bieng used are:
double monthlyInterest = annualInterest / 100 /12;
double loanLengthInMonths = loanLengthInYears * 12;

double monthlyPayment = (loanAmount * monthlyInterest) / (1 - Math.pow((1 + monthlyInterest), loanLengthInYears));

System.out.println("MortgageCalculator");
System.out.println("Annual Interest: 5.75%");
System.out.println("Loan Amount: \$200,000");
System.out.println("Loan Length: 30 years");
System.out.println("Monthly Payment: " + currencyFormat.format(monthlyPayment));
• December 18th, 2011, 10:28 PM
mwr76
Re: Need help please
What is currencyFormat.format. Are they custom class and method? If they are you will need to post the code. I think what you are looking for is the String.format
method. Take a look at this link: Java Platform SE 7 look at the format method.

Hope it helps
• December 18th, 2011, 10:43 PM
kprofgold
Re: Need help please
Would it make a difference if that last println statement was replaced like this:

package mortgagecalculator;

/**
*
* @author Johnny
*/
public class MortgageCalculator {
public static void main(String[] args) {

}

double annualInterest = 5.75; //This is the annual interest rate
double loanAmount = 200000; //This is the loan amount
double loanLengthInYears = 30; //This is the length of the loan in years

//Formuals bieng used are:
double monthlyInterest = annualInterest / 100 /12;
double loanLengthInMonths = loanLengthInYears * 12;

double monthlyPayment = (loanAmount * monthlyInterest) / (1 - Math.pow((1 + monthlyInterest), loanLengthInYears));

System.out.println("MortgageCalculator");
System.out.println("Annual Interest: 5.75%");
System.out.println("Loan Amount: \$200,000");
System.out.println("Loan Length: 30 years");
System.out.println(monthlyPayment);
• December 18th, 2011, 10:51 PM
Mr.777
Re: Need help please
Quote:

Originally Posted by kprofgold
Would it make a difference if that last println statement was replaced like this:

package mortgagecalculator;

/**
*
* @author Johnny
*/
public class MortgageCalculator {
public static void main(String[] args) {

}

double annualInterest = 5.75; //This is the annual interest rate
double loanAmount = 200000; //This is the loan amount
double loanLengthInYears = 30; //This is the length of the loan in years

//Formuals bieng used are:
double monthlyInterest = annualInterest / 100 /12;
double loanLengthInMonths = loanLengthInYears * 12;

double monthlyPayment = (loanAmount * monthlyInterest) / (1 - Math.pow((1 + monthlyInterest), loanLengthInYears));

System.out.println("MortgageCalculator");
System.out.println("Annual Interest: 5.75%");
System.out.println("Loan Amount: \$200,000");
System.out.println("Loan Length: 30 years");
System.out.println(monthlyPayment);

Does this program even compiling? If no, paste here the errors/exceptions.
• December 18th, 2011, 11:01 PM
kprofgold
Re: Need help please
I get cannot find symbol, identifier expected, and illegal start of type errors
• December 18th, 2011, 11:24 PM
Mr.777
Re: Need help please
Can you copy the errors and paste here?
• December 18th, 2011, 11:34 PM
kprofgold
Re: Need help please
I think this is the error Im not very good at this sorry.

Not able to submit breakpoint LineBreakpoint MortgageCalculator.java : 81, reason: The breakpoint is set outside of any class.
Invalid LineBreakpoint MortgageCalculator.java : 81
User program running
User program finished
• December 19th, 2011, 12:02 AM
Mr.777
Re: Need help please
Well, i don't know why aren't you trying to understand what i mean to say.
Simply,
Code :

```double annualInterest = 5.75; //This is the annual interest rate double loanAmount = 200000; //This is the loan amount double loanLengthInYears = 30; //This is the length of the loan in years     //Formuals bieng used are: double monthlyInterest = annualInterest / 100 /12; double loanLengthInMonths = loanLengthInYears * 12;   double monthlyPayment = (loanAmount * monthlyInterest) / (1 - Math.pow((1 + monthlyInterest), loanLengthInYears));     System.out.println("MortgageCalculator"); System.out.println("Annual Interest: 5.75%"); System.out.println("Loan Amount: \$200,000"); System.out.println("Loan Length: 30 years"); System.out.println(monthlyPayment);```
paste this piece of code inside main() and then check the closing and opening braces.
• December 19th, 2011, 12:31 AM
kprofgold
Re: Need help please
Ok thank you... I was closing the code before I had even inputted anything and I had to restart my NetBeans for the code to run. But now the calculation is off and I think it may be within the math. Here are my results:

MortgageCalculator
Annual Interest: 5.75%
Loan Amount: \$200,000
Loan Length: 30 years
-6214.908191559089 (I know this should a positive # lol)
• December 19th, 2011, 12:53 AM
Mr.777
Re: Need help please
Code :

`(1 - Math.pow((1 + monthlyInterest), loanLengthInYears))`
It's giving the negative value.
• December 19th, 2011, 01:08 AM
kprofgold
Re: Need help please
I still havnt been able to fix the math yet.... but I noticed I am also getting a gray line under my loanLengthInMonths...the error is not a known variable in the current context
• December 19th, 2011, 01:22 AM
Mr.777
Re: Need help please
Quote:

but I noticed I am also getting a gray line under my loanLengthInMonths
It's not an error but it is coz the variable loanLengthInMonths is not being used anywhere after assigning value to it.

Also, i don't know what you are supposed to do, might be the problem in your formulas.
• December 19th, 2011, 01:30 AM
kprofgold
Re: Need help please
Here is what I am supposed to calculate: Calculate and display the monthly payment amount to fully amortize a \$200,000.00 loan over a 30 year term at 5.75% interest. And thank you for all of your help.
• December 19th, 2011, 01:58 AM
kprofgold
Re: Need help please
I think I just figured it out. Heres the code

public class MortgageCalculator {

public static void main(String[] args) {
double annualInterest = 5.75; //This is the annual interest rate
double loanAmount = 200000; //This is the loan amount
double loanLengthInYears = 30; //This is the length of the loan in years

//Formuals bieng used are:
double monthlyInterest = annualInterest /100/12;
double loanLengthInMonths = loanLengthInYears * 12;

double monthlyPayment = (loanAmount * monthlyInterest) * (1 + Math.pow((1 - monthlyInterest), loanLengthInYears));

System.out.println("MortgageCalculator");
System.out.println("Annual Interest: 5.75%");
System.out.println("Loan Amount: \$200,000");
System.out.println("Loan Length: 30 years");
System.out.println(monthlyPayment);
}
}
• December 19th, 2011, 03:06 AM
Mr.777
Re: Need help please
Good Luck.