Results 1 to 3 of 3
  1. #1
    jmartin99 is offline Member
    Join Date
    Mar 2017
    Location
    Southern IL
    Posts
    3
    Rep Power
    0

    Default Help with Composition, Aggregation, and Inheritance Homework

    I am in a programming fundamentals class, CS219 and we are in week 4, Composition, Aggregation, and Inheritance. I am lost on how to write our program for this week.

    The instructions are this:
    For the main java file
    - Instantiate an investor1 object using a two parameter constructor passing the account number 1001 and the initial balance of $2,000
    - Instantiate an investor2 object using a two parameter constructor passing the account number 2001 and the initial balance of $4,000
    - Get input for interest rate (in the format .08 for 8%)
    - Use class variable to set interest rate
    - Output header as per sample showing interest rate
    - Print the table using a for loop displaying the current month and calling:
    - addInterest() to add the monthly interest for each iteration
    - getBalance() to display the current balance (See sample)
    - Output results for 15 months.
    - Print the interest earned as shown in the sample for each investor utilizing a printf statement. Donít hard code the interest earned, or interest rate.

    For the Investor java file
    - All variables should be declared private
    - Declare a class variable called interestRate (This will hold the annual interest rate)
    - Declare a constant called ACCOUNT_NUMBER
    - Declare an instance variable called balance
    - Provide a class method that will be used to set the annual interest rate
    - Provide a two parameter constructor to initialize the constant account number and balance
    - Provide an addInterest() method to update the balance based on the interestRate entered in the driver.
    - Add the interest using (balance * interestRate / 12)

    I am just lost on how the whole logic flows for this. Do I need to create an array in the main file to store the monthly balances? Do I need to make an array in the investor file to calculate the month by month interest to multiply the balance by to get the monthly interest to add to the beginning balance?

    Any help with this is greatly appreciated!

    Jeff

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Help with Composition, Aggregation, and Inheritance Homework

    Take the instructions one by one.
    Create an Investor class as per the instructions.
    in main:
    - Instantiate an investor1 object ...
    - Instantiate an investor2 object ...
    and continue as per the instructions.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Help with Composition, Aggregation, and Inheritance Homework

    Do I need to create an array in the main file to store the monthly balances? Do I need to make an array in the investor file to calculate the month by month interest to multiply the balance by to get the monthly interest to add to the beginning balance?
    This is where you need to think about what is being asked. For example, do you need to keep the values and use them over and over again?

    Java Code:
    int[] sum = new int[10];
    int v = 1;
    for (int j = 0; j < 10; j++ ) {
       v = v + j;
     sum[j]  = v;
    }
    // now use them later.
    for (int j = 0; j  < 10; j++) {
       System.out.println(sum[j]);
    }
    Or are you just required to use them as you create them

    Java Code:
    int v = 1;
    for (int j = 0; j < 10; j++) {
       v = v + j;
       System.out.println(v);
    }
    It all depends on what is required. And once you decide what you need to do in any aspect of writing the program, there are probably going to be multiple ways of doing it.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 1
    Last Post: 08-04-2012, 04:50 AM
  2. Composition and Inheritance
    By BeyondWorldsEnd in forum New To Java
    Replies: 3
    Last Post: 01-08-2012, 10:19 AM
  3. Composition vs inheritance
    By mindus in forum Advanced Java
    Replies: 3
    Last Post: 09-27-2010, 07:41 AM
  4. composition Vs Inheritance
    By mindus in forum New To Java
    Replies: 1
    Last Post: 09-26-2010, 07:53 PM
  5. inheritance and aggregation
    By java_fun2007 in forum New To Java
    Replies: 3
    Last Post: 12-13-2007, 01:36 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
  •