Results 1 to 7 of 7
  1. #1
    icedragon770 is offline Member
    Join Date
    Oct 2008
    Posts
    36
    Rep Power
    0

    Default 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

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    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.

  3. #3
    icedragon770 is offline Member
    Join Date
    Oct 2008
    Posts
    36
    Rep Power
    0

    Default

    After year 1: $104.00
    After year 2: $104.00
    is the output for every year
    after year 1 its the same 104.00

  4. #4
    icedragon770 is offline Member
    Join Date
    Oct 2008
    Posts
    36
    Rep Power
    0

    Default

    not really dont know how can u help norm

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    totalBalance= (balanceAccount*1.04);
    If you never change the value of balanceAccount, the results will always be the same.
    Have you tried to do it on a piece of paper to see the logic flow?

  6. #6
    icedragon770 is offline Member
    Join Date
    Oct 2008
    Posts
    36
    Rep Power
    0

    Default

    yea but where should it be put

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    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.

Posting Permissions

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