Results 1 to 9 of 9
- 10-15-2008, 03:30 AM #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!!!!!!
-
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.
-
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 [code] at the top of your block of code and the tag [/code] at the bottom, like so:
Java Code:[code] // your code block goes here. // note the differences between the tag at the top vs the bottom. [/code]
- 10-15-2008, 03:42 AM #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.
temp = JOptionPane.showInputDialog(null,"What is your initial deposit into your 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.
temp = JOptionPane.showInputDialog(null,"What is your Expected APR on your 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);
}
}
- 10-15-2008, 03:42 AM #5
Member
- Join Date
- Oct 2008
- Posts
- 4
- Rep Power
- 0
sorry i think i posed that wrong. im new to the forum too
- 10-15-2008, 03:56 AM #6
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.I think i need to do a loop but Im not sure.
- 10-15-2008, 04:07 AM #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?
-
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.
- 10-15-2008, 01:44 PM #9
Similar Threads
-
pls help me fast!
By rexson98 in forum New To JavaReplies: 10Last Post: 10-15-2008, 12:20 PM -
calculating Bank interest rate.
By dotnet007 in forum New To JavaReplies: 10Last Post: 05-13-2008, 09:30 AM -
Java Calculator
By aapanju in forum New To JavaReplies: 3Last Post: 04-17-2008, 05:33 AM -
calculator not working
By Renegade85 in forum New To JavaReplies: 5Last Post: 03-10-2008, 03:27 PM -
Swing Calculator
By nemo in forum AWT / SwingReplies: 1Last Post: 05-28-2007, 11:07 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks