Exercise 2: Using Collections to Represent Association (Level 2)
In this exercise, you will use generic collections to represent class
associations in the Bank project domain model.
Task 1 - Modifying the Bank Class
Using a text editor, modify the Bank class source file in the src/com/mybank/domain/ directory. This class must satisfy the UML
diagram in Figure 9-2 on page Lab 9-11.
- Modify the declaration for the customers attribute to be of type List<Customer>, and drop the numberOfCustomers attribute.
- Modify the static block to initialize the customers attribute to be a
new ArrayList object.
- Modify the addCuatomer method to use the add method.
- Modify the getCustomer method to use the get method.
- Modlfy the getNumOfCustomers method to use the size method.
Task 2 - Modifying the Customer Class
Using a text editor, modify the Customer class source file in the src/com/mybank/domain/ directory. This class must satisfy the UML
diagram in Figure 9-2 on page Lab 9-11.
-
Modify the declaration for the accounts attribute to be of type List<Account>, and drop the numberOfAccounts attribute.
- Modify the constructor to initialize the accounts attribute to be a
new ArrayList object.
- Modify the addAccount method to use the add method.
- Modify the getAccount method to use the get method.
- Modify the getNumOfAccounts method to use the size method.
Task 4 - Compiling the TestReport Program
On the command line, use the javac command to compile the test
program.
Task 5 - Running the TestReport Program
On the command lime, use the java command to run the test program.
You should see the output listed in "Task 4 - Running the TestReport Program" on page Lab 9-13.