Make your own free website on Tripod.com

5. Objects and Classes (2)

Lab Exercise 5-1: Create Customer Accounts

Objective

In this exercise you will expand the Banking project by adding a Customer class. A customer will contain one Account object.

The UML Diagram of the Customer Class

Note: You should know the UML notations to understand this diagram. For example, the account relationship can be implemented as a data attribute in the Customer class; even though, it is not mentioned in the "attributes" section of the Customer class block.

Directions

Start by changing your working directory to lab05/exercise1 on your computer.

  1. Make the banking directory.
  2. Copy the Banking project files from the previous Banking lab to this directory.
  3. Create the Customer class in the file Customer.java under the banking directory. This directory represents the Java package structure for your program. This class must implement the model in the above UML diagram.
    1. declare three private object attributes: firstName, lastName, and account
    2. declare a public constructor that takes two parameters (f and l) that populate the object attributes
    3. declare two public accessors for the object attributes; these methods getFirstName and getLastName simply return the appropriate attribute
    4. declare the setAccount method to assign the account attribute
    5. declare the account method to retrieve the account attribute
  4. In the main exercise1 directory, compile and run the TestBanking program. You shoud see the following output:
    Creating the customer Jane Smith.
    Creating her account with a 500.00 balance.
    Withdraw 150.00
    Deposit 22.50
    Withdraw 47.62
    Customer [Smith, Jane] has a balance of 324.88