# Thread: Clueless as to what is wrong.

1. Member
Join Date
Sep 2012
Posts
2
Rep Power
0

## Clueless as to what is wrong.

I have written some code to "print out three lines for each loan, giving the amount of monthly payments, the interest paid over the life of the loans, and the total amount paid back over the life of the loan, with appropriate wording."
I was given a formula to figure out the monthly payment and I get the monthly payment that is given so I know for a fact that the formula in my code is right. But the problem is somewhere where I calculate the interest and total amount paid.
Java Code:
```import java.io.*;
import java.util.*;

public class Interest
{
{
Scanner Console = new Scanner(System.in);
System.out.print("The amount I wish to borrow: ");
double Borrowed = Console.nextDouble();

System.out.print("The loan rate I can get is: ");
double Rate = Console.nextDouble();

System.out.print("The number of months it will take me to pay off the loan is: ");
double Month = Console.nextDouble();

double MP = Borrowed * (Rate/1200.0) * Math.pow(1+Rate/1200.0,Month)/(Math.pow(1+Rate/1200.0,Month)-1);
System.out.println(" ");

double newMP = Math.round(MP*100.0)/100.0;
System.out.println("The monthly payment will be: " + newMP);

double totalinterest = (newMP*Month)-Borrowed;
double newtotalinterest = Math.round(totalinterest*100.0)/100.0;
System.out.println("The total amount of interest paid is: " + newtotalinterest);

double Totalpaid = newMP*Month;
System.out.println("The total amount paid is: " + Totalpaid);```
When you run the program, these numbers should be typed in:

The amount I wish to borrow is? 7500
The loan rate I can get is? 14.5
The number of months it will take me to pay off the loan is? 36

The numbers you should be getting are:
My monthly payments will be \$ 258.16
Total Interest Paid is \$ 1793.66
Total Amount paid is \$ 9293.66

My monthly payment number is the same as the one given but my Total Interest paid and Amount paid are off by 10 cents. I have been thinking about this problem all day and can not find a solution. It is probably staring me right in the face but can anyone LEAD me in the right direction?

2. Member
Join Date
Sep 2012
Posts
26
Rep Power
0

## Re: Clueless as to what is wrong.

First of all statements can only be executed in methods.

3. ## Re: Clueless as to what is wrong.

Please go through the Forum Rules -- particularly the third paragraph.

db

4. ## Re: Clueless as to what is wrong.

If you're not using an IDE to create your programs, you'll want to compile your code early and often and making sure to fix any compilation errors before trying to add new code. That would have saved you a lot of trouble here in your program above.

5. Member
Join Date
Sep 2012
Posts
2
Rep Power
0

## Re: Clueless as to what is wrong.

Originally Posted by Fubarable
If you're not using an IDE to create your programs, you'll want to compile your code early and often and making sure to fix any compilation errors before trying to add new code. That would have saved you a lot of trouble here in your program above.
I'm using BlueJ. No, don't suggest me others or say how bad it is. The program runs, like I stated above, but I am off 10 cents which is my problem.

6. ## Re: Clueless as to what is wrong.

Originally Posted by Biscuittickler
The program runs, like I stated above
The code you posted won't run. Heck, it won't even crawl.

db

7. ## Re: Clueless as to what is wrong.

Originally Posted by Biscuittickler
I'm using BlueJ. No, don't suggest me others or say how bad it is. The program runs, like I stated above, but I am off 10 cents which is my problem.
No, the code you've posted won't even compile, since as pointed out, you've got statements sitting out naked in the class when they should be within a main method (which the class doesn't even have). If you have different code that's actually compiling and running, and if you're still having problems, then you'll want to post the new code and not waste our time with code that doesn't reflect the current problem and that doesn't run.

8. Member
Join Date
Sep 2012
Posts
68
Rep Power
0

## Re: Clueless as to what is wrong.

Your in my AP Computer Scinece class... Just thought id throw that out there

#### Posting Permissions

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