Exercise 1:Creating Bank Account Subclasses (Level  1)


In this exercise, you will create two subclasses of the Account class in the Banking project: SavingsAccount  and CheckingAccount. These account  types have the  following business rules.

Figure 6-1 shows the UML class diagram for a design that satisfies the business rules described above.


Figure 6-1 Two Subclasses of the Account Class




Preparation

Before you begin, make sure that you have changed directories to projects/BankingPrj/ using the cd command  in the terminal de window.

cd ~/ projects/ BankingPrj/

Task 1 - Modifying the Account Class

Using a text editor, modify the Account class source file in the src/ com/ mybank/ domain directory. This class must satisfy the UML diagram in Figure 6-1 on page Lab 6-2; in particular, the balance attribute and Account class constructor are now  protected (indicated by the # character instead of the   -  character ).

Task 2 - Creating the SavingsAccount Class

Using a text editor, create the SavingsAccount class source file in the  src/com/mybank/domain/ directory. This class must satisfy the UML diagram in Figure 6-1 on page Lab 6- 2 and the business rules defined in the introduction to "Exercise 1: Creating Bank Account Subclasses (Level 1)" on page  Lab 6-2.

Task 3 - Creating the CheckingAccount Class

Using a text editor, create the CheckingAccount class source file in the  src/com/mybank/domain/ directory. This class must satisfy the UML diagram in Figure 6-1 on page Lab 6- 2 and the business rules defined in the introduction to "Exercise 1: Creating Bank Account Subclasses (Level 1)" on page  Lab 6-2.

Task 4 - Copying the TestBanking Class

Copy the TestBanking.java file file from the resources/mod06_class1/ directory into the src/com/mybank/test directory.

Task 5 - Compiling the  TestBanking Program

On the command line, use the javac command to compile the test program.

Task 6 - Running the  TestBanking Program

On the command line, use the java command to run the test program. You should see the following output:

Creating the customer Jane Smith.
Creating her Savings Account with a 500.00 balance and 3% interest.
Creating the customer Owen Bryant.
Creating his Checking Account with a 500.00 balance and no overdraft protection.
Creating the customer Tim Soley.
Creating his Checking Account with a 500.00 balance and 500.00 in overdraft protection.
Creating the customer Maria Soley.
Maria shares her Checking Account with her husband Tim.

Retrieving the customer Jane Smith with her savings account.
Withdraw 150.00: true
Deposit 22.50: true
Withdraw 47.62: true
Withdraw 400.00: false
Customer [Simms, Jane] has a balance of 324.88

Retrieving the customer Owen Bryant with his checking account with no overdraft protection.
Withdraw 150.00: true
Deposit 22.50: true
Withdraw 47.62: true
Withdraw 400.00: false
Customer [Bryant, Owen] has a balance of 324.88

Retrieving the customer Tim Soley with his checking account that has overdraft protection.
Withdraw 150.00: true
Deposit 22.50: true
Withdraw 47.62: true
Withdraw 400.00: true
Customer [Soley, Tim] has a balance of 0.0
Retrieving the customer Maria Soley with her joint checking account with husband Tim.
Deposit 150.00: true
Withdraw 750.00: false
Customer [Soley, Maria] has a balance of 150.00

Jane´s savings account and Owen´s checking account behave fundamentally as a basic bank account. But Tim and Maria´s joint ckecking account has 500.00 worth of overdraft protection. Tim´s transactions dip into that protection and therefore his ending balance is 0.00. His  account´s overdraft protection level is 424.88. Finally, Maria deposits 150.00 into this joint account; raising the balance from 0.00 to 150.00. Then she tries to withdraw 750.00, which fails because neither the balance nor the overdraft protection can cover that requested amount.