5. Objects and Classes (2)
Lab Exercise 5-1: Create Customer Accounts
In this exercise you will expand the Banking project by adding a Customer
class. A customer will contain one Account object.
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.
Start by changing your working directory to lab05/exercise1 on your
- Make the banking directory.
- Copy the Banking project files from the previous Banking lab to this
- 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.
- declare three private object attributes: firstName, lastName,
- declare a public constructor that takes two parameters (f
and l) that populate the object attributes
- declare two public accessors for the object attributes; these methods
getFirstName and getLastName simply return the appropriate
- declare the setAccount method to assign the account
- declare the account method to retrieve the account
- 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.
Customer [Smith, Jane] has a balance of 324.88