Practice Questions: Week 07


Aggregation, Composition, and Copying

1. Write a program that creates an Investment object and shows that Investment is an aggregation of a Stock object.

2. Write a program that creates a CreditCard object and shows that CreditCard is a composition of at least 2 Date objects.

3. (Relies on Week 10) Write a program that creates an ArrayList<Fraction> and add one or more Fractions to the list. Is ArrayList<Fraction> an aggregation or composition of Fractions? Your program should answer the question.

4. Write a program that creates a random Investment object. Make a shallow copy of the investment and prove that it is indeed a shallow copy.

5. See Question 4; make a deep copy and prove that it is a deep copy (at least from the client's point of view).

6. Suppose some one gave you a shallow copy of a CreditCard; would this surprise you? Why? What would this person had to have done in order to accomplish the shallow copy?

Far beyond the scope of CSE1020

7. Create a shallow copy of a CreditCard instance and prove that it is a shallow copy; you will have to go well beyond the scope of CSE1020 and CSE1030 to answer this question.