Results 1 to 7 of 7
Thread: CompoundInterest.java
- 10-18-2008, 08:41 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 36
- Rep Power
- 0
CompoundInterest.java
import javax.swing.*;
public class CompoundInterest
{
public static void main(String args[])
{
// Declare and initialize variables here.
String accountNumberstring;
String accountFirstnamestring;
String accountLastnamestring;
String balanceString;
double accountNumber;
int count=0;
double balanceAccount;
double totalBalance;
// Get input and convert to correct data type
accountNumberstring = JOptionPane.showInputDialog("Please enter your account number: ");
accountFirstnamestring = JOptionPane.showInputDialog("Please enter your first name: ");
accountLastnamestring = JOptionPane.showInputDialog("Please enter your last name: ");
balanceString = JOptionPane.showInputDialog("Please enter the value of your deposit: ");
accountNumber = Double.parseDouble(accountNumberstring);
balanceAccount = Double.parseDouble(balanceString);
while(count < 20)
{ totalBalance= (balanceAccount*1.04);
count = count +1;
System.out.println("Future value of Account" + accountNumber + "for" + accountName);
System.out.println("After year " + count + ": $" + totalBalance);
}
System.exit(0);
}
}
my out put needs to be
Future Value of Account ACC 12345 for Mike Flint
After year 1: $104.0
After year 2: $108.16
After year 3: $112.4864
After year 4: $116.98585600000001
After year 5: $121.66529024000002
After year 6: $126.53190184960002
After year 7: $131.59317792358402
After year 8: $136.85690504052738
After year 9: $142.3311812421485
After year 10: $148.02442849183444
After year 11: $153.94540563150784
After year 12: $160.10322185676816
After year 13: $166.50735073103888
After year 14: $173.16764476028044
After year 15: $180.09435055069167
After year 16: $187.29812457271936
After year 17: $194.79004955562814
After year 18: $202.58165153785328
After year 19: $210.68491759936742
After year 20: $219.11231430334212
- 10-18-2008, 09:06 PM #2
Ok you've shown what it needs to be.
What does it output now? How do they differ?
You don't need to show all 20 years, 3 would be enough.
Have you done the arithmetic on paper to see how the logic should flow? What is computed, what is added to what etc.
- 10-18-2008, 09:08 PM #3
Member
- Join Date
- Oct 2008
- Posts
- 36
- Rep Power
- 0
After year 1: $104.00
After year 2: $104.00
is the output for every year
after year 1 its the same 104.00
- 10-18-2008, 09:24 PM #4
Member
- Join Date
- Oct 2008
- Posts
- 36
- Rep Power
- 0
not really dont know how can u help norm
- 10-18-2008, 09:59 PM #5
If you never change the value of balanceAccount, the results will always be the same.totalBalance= (balanceAccount*1.04);
Have you tried to do it on a piece of paper to see the logic flow?
- 10-19-2008, 07:24 PM #6
Member
- Join Date
- Oct 2008
- Posts
- 36
- Rep Power
- 0
yea but where should it be put
- 10-19-2008, 08:47 PM #7
Can you solve the problem on a piece of paper? You need to design the code before coding it. Have each variable on a separate line: count, totalBalance and balanceAccount.
Iniitialize them and then work thru the logic in your loop, crossing out old values as new ones are assigned. You should see where the hole in your logic is.


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks