Question: Task #1 Extending the BankAccount Class Copy the files AccountDriver.java (Code Listing 10.1) and BankAccount.java(Code Listing 10.2) from the Student CD or as directed by

Task #1 Extending the BankAccount Class

Copy the files AccountDriver.java (Code Listing 10.1) and BankAccount.java(Code Listing 10.2) from the Student CD or as directed by your instructor.BankAccount.java is complete and will not need to be modified.

Create a new class called CheckingAccount that extends BankAccount.

It should contain a static constant FEE that represents the cost of clearing one

check. Set it equal to 15 cents.

Write a constructor that takes a name and an initial amount as parameters. It

should call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenated with 10 (All checking accounts at this bank are identified by the extension 10). There can be only one checking account for each account number. Remember since accountNumber is a private member in BankAccount, it must be changed through a mutator method.

Write a new instance method, withdraw, that overrides the withdraw method in the superclass. This method should take the amount to withdraw, add to it the fee for check clearing, and call the withdraw method from the superclass. Remember that to override the method, it must have the same method heading. Notice that the withdraw method from the superclass returns true or falsedepending if it was able to complete the withdrawal or not. The method that overrides it must also return the same true or false that was returned from the call to the withdraw method from the superclass.

Compile and debug this class.

Task #2 Creating a Second Subclass

Create a new class called SavingsAccount that extends BankAccount.

It should contain an instance variable called rate that represents the annual

interest rate. Set it equal to 2.5%.

It should also have an instance variable called savingsNumber, initialized to 0.

In this bank, you have one account number, but can have several savings accounts with that same number. Each individual savings account is identified by the number following a dash. For example, 100001-0 is the first savings account you open, 100001-1 would be another savings account that is still part of your same account. This is so that you can keep some funds separate from the others, like a Christmas club account.

An instance variable called accountNumber, that will hide theaccountNumber from the superclass, should also be in this class.

Write a constructor that takes a name and an initial balance as parameters and calls the constructor for the superclass. It should initialize accountNumber to be the current value in the superclass accountNumber (the hidden instance variable) concatenated with a hyphen and then the savingsNumber.

Copyright 2016 Pearson Education, Inc., Hoboken NJ

Write a method called postInterest that has no parameters and returns no value. This method will calculate one month's worth of interest on the balance and deposit it into the account.

Write a method that overrides the getAccountNumber method in the superclass.

Write a copy constructor that creates another savings account for the same person. It should take the original savings account and an initial balance as parameters. It should call the copy constructor of the superclass, and assign thesavingsNumber to be one more than the savingsNumber of the original savings account. It should assign the accountNumber to be theaccountNumber of the superclass concatenated with the hyphen and thesavingsNumber of the new account.

Compile and debug this class.

Use the AccountDriver class to test out your classes. If you named and

created your classes and methods correctly, it should not have any difficulties. If you have errors, do not edit the AccountDriver class. You must make your classes work with this program.

Running the program should give the following output:

Account Number 100001-10 belonging to Benjamin Franklin Initial balance = $1000.00 After deposit of $500.00, balance = $1500.00 After withdrawal of $1000.00, balance = $499.85 
Account Number 100002-0 belonging to William Shakespeare Initial balance = $400.00 After deposit of $500.00, balance = $900.00 Insufficient funds to withdraw $1000.00, balance = $900.00 After monthly interest has been posted, balance = $901.88 
Account Number 100002-1 belonging to William Shakespeare Initial balance = $5.00 After deposit of $500.00, balance = $505.00 Insufficient funds to withdraw $1000.00, balance = $505.00 
Account Number 100003-10 belonging to Isaac Newton 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!