Results 1 to 2 of 2
  1. #1
    TitanVex is offline Member
    Join Date
    Nov 2011
    Posts
    1
    Rep Power
    0

    Default Help with returning 'set' commands

    I am fairly new to java. I have to make a program about a Savings Account. In one class, I have defined the following:

    private double interest;

    ....

    public double getInterest() {
    return interest;
    }

    public void setInterest(double interest) {
    interest = (newBalance * (interestRate/12)) + newBalance;
    }

    I then make a demo class to test it. However, I am not sure what I have to do to make the variable work. I have defined the variable interestTotal, but I can't get the 'one.setInterest()' to work, no matter what I put in it. All I want is for the 'one.setInterest()' to call upon its command (from up above) if that is possible.

    interestTotal = interestTotal + one.setInterest();

    Like I said, I am fairly new to java so I am pretty baffled right now. Any help is appreciated. Ideally, I would rather have the command to be something like:

    one.setInterest = one.setInterest() + one.getInterest();

    But that doesn't work either....
    Thanks a lot.

    -TitanVex

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

    Default Re: Help with returning 'set' commands

    I'm not sure that you should have an interest field or a setInterest(...) method. Instead consider having just a getInterest method, one that calculates the value based on the current newBalance and InterestRate value.

Similar Threads

  1. Commands on java.
    By Slithice in forum New To Java
    Replies: 15
    Last Post: 11-15-2012, 11:06 AM
  2. using RMAN commands in Java
    By mario_tim in forum JDBC
    Replies: 4
    Last Post: 03-22-2011, 05:59 AM
  3. At commands in java
    By strictlydivine.elite in forum Advanced Java
    Replies: 1
    Last Post: 11-22-2010, 10:55 AM
  4. CMD is not reading commands
    By colonial in forum Forum Lobby
    Replies: 1
    Last Post: 03-15-2010, 03:36 AM
  5. InFile Commands not being recognized.
    By Tenn in forum New To Java
    Replies: 4
    Last Post: 02-13-2009, 04:50 PM

Posting Permissions

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