Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1 . Class hierarchy (30 points) You are asked to create new classes call

ID: 3771081 • Letter: P

Question

Problem 1. Class hierarchy (30 points)

You are asked to create new classes called BankAccount, SavingsAccount, CheckingAccount. A checking account is a bank account and a savings account is a bank account as well. This setup is clearly an inheritance relationship among those classes. I include for you the UML Class Diagram so that you can use to implement it.

Create a new class called BankAccount that has three private variables (balance, owner, accountNumber) and one protected static variable (numberOfAccounts) that initialize to 100001 then it is increment by one every time a new account being created.

Write a default constructor and two constructors that takes a name and an amount amount as parameters and takes a bank account object and an amount as parameters as well.

Write those accessor and mutator methods according to the UML class diagram of the BankAccount including an override toString method as well.

Create a new class called CheckingAccount

It should contain a static constant FEE that represents the cost of clearing one check. Set it equal to 15 cents.

Write a default constructor and a constructor that takes a name and an initial amount as parameters. It should call the constructor for the superclass. It should in initialize accountNumber 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/setter 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 of false depending 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.

Create a new class called SavingsAccount

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, 1000001-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 the accountNumber from the superclass, should also be in this class.

Write a default constructor and 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.

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

Write a method called postInterest that has no parameter 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

Compile and debug this class and write a test driver class to test/demo your implementation.

HINTS: THIS IS JUST TO SHOW YOU THE SAMPLE OF CONSTRUCTORS IN THE BankAccount Class

Explanation / Answer

Code for class Checking Account which is inherited from class.bankaccount.

The man function and the class:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote