Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Need help with java compound interest

  • 06-11-2008 12:01pm
    #1
    Closed Accounts Posts: 4


    im a first year student doing java programing and im having alot of trouble with dis question. Iv been asked 2 write a piece of code to calculate compound interest for a year while calculating it each month. I was advised to use a for loop ut i could no gt it to work. i am now trying the following but im continuosly being tod to enter a extra bracket;
    public double calculateInterest()
    {
        do
        {
            (i=1; i<2; i++;)
            
            1 + depInterestRate / 12 = amount * (12 * 1)= 
            newBalance * balance = newbalance + balance;
            
        }
        while(i<=12)
    }
    
    thnks 2 veryone in advance for help this is really appreciated.


Comments

  • Moderators, Music Moderators Posts: 23,363 Mod ✭✭✭✭feylya


    You need to calculate compound interest on a sum of money. Firstly, you need to pass the function the amount of money that is earning the interest.

    Then you'll need to have a loop to calculate the interest per month. You were nearly right with what you have in your code:

    for (i=0; i<12; i++)
    {
    //Do something
    }

    To calculate the interest, the total is the money you have times the interest rate plus the money you already have so:

    x = (x*interest) + x

    Once you have that done, you need to return the value you've come up with.


  • Registered Users, Registered Users 2 Posts: 54 ✭✭ejvilla


    Well I haven't looked at the code you're using to do your sums... but there is a problem with your do..while loop syntax.

    Look here for more information:
    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/while.html


    Clue: You're missing one character ;)


  • Registered Users, Registered Users 2 Posts: 54 ✭✭ejvilla


    Okay.. so I looked at the code you have inside the loop.. Is this your first java assignment? You really should read whatever notes they gave you about assigning values to variables... read the first two chapters of whatever java book you've been assigned and you should have all your answers..

    Alternatively, look at the Sun Java Tutorial:

    http://java.sun.com/docs/books/tutorial/
    coxy909 wrote: »
    im a first year student doing java programing and im having alot of trouble with dis question. Iv been asked 2 write a piece of code to calculate compound interest for a year while calculating it each month. I was advised to use a for loop ut i could no gt it to work. i am now trying the following but im continuosly being tod to enter a extra bracket;
    public double calculateInterest()
    {
        do
        {
            (i=1; i<2; i++;)
            
            1 + depInterestRate / 12 = amount * (12 * 1)= 
            newBalance * balance = newbalance + balance;
            
        }
        while(i<=12)
    }
    
    thnks 2 veryone in advance for help this is really appreciated.


  • Closed Accounts Posts: 4 coxy909


    ejvilla wrote: »
    Okay.. so I looked at the code you have inside the loop.. Is this your first java assignment? You really should read whatever notes they gave you about assigning values to variables... read the first two chapters of whatever java book you've been assigned and you should have all your answers..

    Alternatively, look at the Sun Java Tutorial:

    http://java.sun.com/docs/books/tutorial/

    thnks 4 da help ya its my first proper 1 jus find loops really hard for some reason thanks again


  • Closed Accounts Posts: 4 coxy909


    feylya wrote: »
    You need to calculate compound interest on a sum of money. Firstly, you need to pass the function the amount of money that is earning the interest.

    Then you'll need to have a loop to calculate the interest per month. You were nearly right with what you have in your code:

    for (i=0; i<12; i++)
    {
    //Do something
    }

    To calculate the interest, the total is the money you have times the interest rate plus the money you already have so:

    x = (x*interest) + x

    Once you have that done, you need to return the value you've come up with.


    thnks man dat helpa a serious amount didnt no what i was doing wrong i completly forgot about the value il give it a try hopefully everything will go ok from der


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    coxy909 wrote: »
    thnks 2 veryone in advance for help this is really appreciated.

    Can you explain in detail what each of the lines you wrote was supposed to do.


  • Closed Accounts Posts: 4 coxy909


    Hobbes wrote: »
    Can you explain in detail what each of the lines you wrote was supposed to do.

    em basically
    the do statement is meant to calculate the interest each month for my customer i was told to use a if statement by anova class member and tried this jus now but it would not compile either saying it expected ) this new code is below
    public void calculateInterest()

    {
    for (int i;i<12;i++;)
    {
    balance = balance * (1 + (depInterestRate/12)) * 12;
    }
    return balance;
    }
    }

    if u can help wit either thnks a mill

    public double calculateInterest()
    {
    do
    {
    (i=1; i<12; i++;)

    1 + depInterestRate / 12 = amount * (12 * 1)=
    newBalance * balance = newbalance + balance;

    }
    while(i<=12)
    }


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    No I mean you explain each line. not the code as a whole.


Advertisement