Results 1 to 3 of 3
  1. #1
    ModestMariner is offline Member
    Join Date
    Mar 2013
    Posts
    4
    Rep Power
    0

    Default Add two objects of the same class

    In my java class my instructor is wanting us to create a program that calculates the amount of interest accrued on an account per year and displays the amount that is in that account every month.

    So a sample runtime of this is as follows:

    In the main method I create two classes, one for the balance account and the other for the monthly deposit.

    So I have two objects of the same class.

    Then I'm asked to enter the amount for the first object which I'll call the "balance."
    Then I enter the dollar amount separated by a space and the cent amount for the balance.
    The balance object then takes these two values and stores them to two separate variables, one for dollars and one for cents.

    Then I enter the deposit amount.
    and it does the same as above.

    Then i enter the percentage of the interest rate.

    Then I enter how many years I want it to run for.

    Then it goes into a for-loop structure.

    In the body of the loop, it first calculates the amount of interest that will be added to the balance.

    then it adds the new balance to the deposit object

    and then it outputs the total amount of the balance, and then loops through it again.

    My issue is adding the balance object to the deposit object.
    I have a method in this account class called "add" and so far I know that the structure should look something like this:

    public void add(MonetaryValue addend)
    {
    (But I have no idea what goes here or how to get this to work.)
    }

    Can anyone help me? Thanks!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Add two objects of the same class

    You didn't bother to reply to the two useful responses in your earlier thread: Comparing multiple string values Why should we expect better behavior this time round?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    ModestMariner is offline Member
    Join Date
    Mar 2013
    Posts
    4
    Rep Power
    0

    Default Re: Add two objects of the same class

    Thanks! I'll just check with a different forum.

Similar Threads

  1. objects from non static class
    By stuckonjava in forum New To Java
    Replies: 4
    Last Post: 05-15-2012, 07:55 PM
  2. array of class objects
    By ravi1912 in forum New To Java
    Replies: 1
    Last Post: 08-08-2011, 10:58 AM
  3. How to use class objects in arrays
    By dironic88 in forum Eclipse
    Replies: 6
    Last Post: 04-06-2011, 02:34 PM
  4. Replies: 1
    Last Post: 01-03-2010, 10:48 PM
  5. Getting objects of a class
    By ravian in forum New To Java
    Replies: 1
    Last Post: 12-04-2007, 01:23 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
  •