1. Member
Join Date
Oct 2008
Posts
4
Rep Power
0

HELP FAST!!----Interest Calculator

Hey guys. Im new to here and new to Java. My class is doing a simple assignment to compute interest on a initial deposit in the bank for 1,5,10,20,30 years. I have to print the current balance at the end of each time frame. I cant figure out how to get the interest for each month COMPOUNDED upon each other. For example) a deposit of \$100 at .01 interest would not be \$112 at the end of year 1, it would be more because you earn interest on the interest already earned for every month. I think i need to do a loop but Im not sure. HELP WITH SINTAX!!!!!!

2. 1) First of all, please take a deep breath and try to calm down. Yelling in your post is not going to endear you to those who might otherwise help you.
2) Please show us your code attempt and problems with it, how it doesn't work, what specific errors it shows.

Good luck.

3. Oh, also, please have a look here at the mathematics of compound interest: Compound interest - Wikipedia, the free encyclopedia

Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, you will need to paste already formatted code into the forum, highlight this code, and then press the "code" button. Another way is to place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:

Java Code:
```&#91;code]
// your code block goes here.
// note the differences between the tag at the top vs the bottom.
&#91;/code]```

4. Member
Join Date
Oct 2008
Posts
4
Rep Power
0
/*Brent Cooper
Comp 2000
Assignment 3A
Jonathon Lartigue*/

//Import your JOptionPane to enable your program to run the dialog box.
import javax.swing.JOptionPane;
//Assign your program a class name which must match your save name.
class interest
{
public static void main(String[] args)
{
//Assign the correct keywords to your values in the program. I used double to represent dollar amounts
//with 2 places. I used int for my months which will be suffecient for an account that is open for a
//long time.
double interestRate;
double balance;
double interestEarned;
double newBalance;
int numberMonths;
//I used string temp to enable me to convert the input amount in the dialog box into a double.
String temp;

//After the input is typed into the dialog box, the amount is put in double form. This input box
//assigns the Initial Deposit put into the account.
balance = Double.parseDouble(temp);

//After the input is typed into the dialog box, the amount is put in double form again. This input box
//assigns the APR given to the account.
interestRate = Double.parseDouble(temp);

//This prints the Initial Deposit on the screen.
System.out.println(balance);

//This calculates the New Balance after 1 year has passed and the APR has been compounded to the Initial
//Deposit of the account. The New Balance after compounding is printed to the screen.
numberMonths = 12;
newBalance=(balance+(balance*interestRate*numberMo nths));
System.out.println(newBalance);

//This calculates the New Balance after 5 years have passed and the APR has been compounded to the Initial
//Deposit of the account. The New Balance after compounding is printed to the screen.
numberMonths = 60;
newBalance=(balance+(balance*interestRate*numberMo nths));
System.out.println(newBalance);

//This calculates the New Balance after 10 years have passed and the APR has been compounded to the
//Initial Deposit of the account. The New Balance after compounding is printed to the screen.
numberMonths = 120;
newBalance=(balance+(balance*interestRate*numberMo nths));
System.out.println(newBalance);

//This calculates the New Balance after 20 years have passed, and the APR has been compounded to the
//Initial Deposit of the account. The New Balance after compounding is printed to the screen.
numberMonths = 240;
newBalance=(balance+(balance*interestRate*numberMo nths));
System.out.println(newBalance);

//This calculates the New Balance after 30 years have passed, and the APR has been compounded to the
//Initial Deposit of the account. The New Balance after compounding is printed to the screen.
numberMonths = 360;
newBalance= (balance+(balance*interestRate*numberMonths));
System.out.println(newBalance);
}
}

5. Member
Join Date
Oct 2008
Posts
4
Rep Power
0
sorry i think i posed that wrong. im new to the forum too

6. I think i need to do a loop but Im not sure.
Have you tried working out the problem on a piece of paper first to see how the calculations flow? You should be able to see a pattern as you work it step by step that will help you decide how to code a loop.

7. Member
Join Date
Oct 2008
Posts
4
Rep Power
0
yeah i understand the math problem.

Month 1- Earn 0.1% on \$100 = new balance is \$101
Month 2- Earn 0.1% on \$101 = new balance is \$102.01
Month 3- Earn 0.1% on \$102.01 =new balance is \$103.0301

and i need to keep 2 significant digits after the decimal. does double do that?

8. fishtoprecords will have a lot to say about this question. He'll recommend (and rightfully so) that you should never use floating point numbers to represent currency, though you may have no choice here if your instructor requires that you do so.

9. I'd think the number of decimal places you need to carry before rounding would be important.
For example the sum: 1.004 + 1.004 + 1.004
Round before adding will be 3.00