Exercise 1: Applying Static Members to a Design (Level 1)
In this exercise, you will apply static class members to resolve a
design decision. The Banking Project uses currently a concrete class to
represent the concept of a bank, which contains the set of customers of
the bank. The project team has decided that this is a risky design
because it would be possible to instantiate multiple Bank objects each
with the potential to contain different sets of customers.
The design team has decided to make the Bank class a utility class. A
utility class is one that is not instantiated and all of its members
are static. Figure 7-1 shows the new design for the Bank class. Your
job is to program these changes to the Bank class and to all of the
classes tha use the Bank class.
Preparation
Before you begin, make sure that you have changed directories to
projects/BankingPrj/ using the cd command in the terminal window.
cd ~/projects/BankingPrj/
Task 1 - Modifying the Bank Class
Using a text editor, modify the Bank class source file un the
src/com/mybank/domain/ directory. Modify the Bank class to convert
instance members (both attributes and methods) to static members.
Task 2 - Modifying the CustomerReport Class
Using a text editor, modify the Customerreport class source file in the
src/com/mybank/report/ directory. Modify the CustomerReport class to
use the Bank class a utility class.
Task 3 - Copying the TestReport Program
Copy the TestReport .java file from the resources/mod07_class2/ directory into the src/com/mybank/test/ directory.
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 line, use the java command to run the test program. Yo
should see the same output from previous tests as shown in "Task 4 -
Compiling the TestReport Program" on page Lab 6-14.