Results 1 to 4 of 4
  1. #1
    trueblue is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default [SOLVED] Why does the compiler return "not a statement" for this method body please?

    getBalance() and getInterestRate() both return doubles.

    Java Code:
    public void addInterest()
       {
          (this.getBalance() * this.getInterestRate()) / 100;
       }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You are multiplying two numbers, then dividing by 100, but what do you want to do with the result? My guess is that you want to either have the method return this result or else add this interest that you calculated to a variable, perhaps you want to add it to the balance.

    So bottom line, either have the method return something (and if so, be sure that the return type is changed from void to double), or else use the number you calculate in a statement that has a variable on the left side of an equals sign, and this calculation on the right.

  3. #3
    trueblue is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    You are multiplying two numbers, then dividing by 100, but what do you want to do with the result? My guess is that you want to either have the method return this result or else add this interest that you calculated to a variable, perhaps you want to add it to the balance.

    So bottom line, either have the method return something (and if so, be sure that the return type is changed from void to double), or else use the number you calculate in a statement that has a variable on the left side of an equals sign, and this calculation on the right.
    Hi, thanks for your reply. I realised after I had made the post that the statement was pretty much directionless so I immediately marked it solved.
    I was working in the early hours and I think the birds had just started singing which possibly distracted me :o
    Once again thank you for replying and your continued support.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Great, I wasn't sure, since the post remained. We all have brain-f@rts every now and again.

Similar Threads

  1. Replies: 0
    Last Post: 03-15-2009, 11:53 PM
  2. Using Dr. Java for first time...."No compiler"
    By gallimaufry in forum New To Java
    Replies: 3
    Last Post: 10-28-2008, 01:02 AM
  3. Replies: 1
    Last Post: 10-20-2008, 07:35 AM
  4. "Any Body Help, Urgent".
    By adeeb in forum NetBeans
    Replies: 5
    Last Post: 05-28-2008, 12:36 PM
  5. How to solve "No compiler error"?
    By iceman in forum New To Java
    Replies: 5
    Last Post: 04-22-2008, 03:37 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
  •