Results 1 to 9 of 9
  1. #1
    Coop33 is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Unhappy 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. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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]

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

    Default

    /*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);
    }
    }

  5. #5
    Coop33 is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default

    sorry i think i posed that wrong. im new to the forum too

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

    Default

    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. #7
    Coop33 is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default

    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. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    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
    after adding will be 3.01

Similar Threads

  1. pls help me fast!
    By rexson98 in forum New To Java
    Replies: 10
    Last Post: 10-15-2008, 12:20 PM
  2. calculating Bank interest rate.
    By dotnet007 in forum New To Java
    Replies: 10
    Last Post: 05-13-2008, 09:30 AM
  3. Java Calculator
    By aapanju in forum New To Java
    Replies: 3
    Last Post: 04-17-2008, 05:33 AM
  4. calculator not working
    By Renegade85 in forum New To Java
    Replies: 5
    Last Post: 03-10-2008, 03:27 PM
  5. Swing Calculator
    By nemo in forum AWT / Swing
    Replies: 1
    Last Post: 05-28-2007, 11:07 AM

Posting Permissions

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