Create an object inheritance hierarchy that a bank might use to represent customer’s bank accounts. Here are the specifications:

Class hierarchy:

  1. Create a Windows Form project.
  2. Add a Class “Account”(base class)anddefine the following members (Use the names given below):
  3. Instance variable balanceValue

Decimal type, stores the account balance

  1. Constructor Sub New

Need one Decimal parameter, initialize instance variable balanceValue using the parameter

  1. Property Balance
  2. Define Get method to return balanceValue
  3. Define Set method

a)If paramater >=0.0, assign it to balanceValue

b)If paramater < 0.0, assign 0.0 to balanceValue.

  1. Sub Credit
  2. Declared as overridable, so its derived classes could override it.
  3. Need one Decimal parameter
  4. Add this parameter to balanceValue
  5. Function Debit
  6. Declared as overridable, so its derived classes could override it.
  7. Return a Boolean value
  8. Need one Decimal parameter
  9. If parameter > balanceValue, then just return False.
  10. If parameter <= balanceValue, deduct parameter value from balanceValue and return True.
  11. Function ToString
  12. Overrides Object’s ToString function
  13. Display account’s balance
  14. Please use the following definition in order to make testing easier.

'overrides ToString() to display account's information

PublicOverridesFunction ToString() AsString

Return (String.Format("Balance: {0:C2}", Balance) & vbCrLf)

EndFunction

  1. Add Class “CheckingAccount”in the project, which inherits from class Accountand includes the following members (Use the names given below):
  2. Instance variable transactionFee

Decimal type, stores the fee chared per transaction

  1. Constructor Sub New
  2. Need two Decimal parameter
  3. Call base class’s constructor to set up base class part
  4. Initializes instance variable transactionFee using parameter’s value, if parameter < 0.0, initialize transactionFee to 0
  5. Property Fee
  6. Define Get method to return transactionFee
  7. Define Set method

a)If paramater >=0.0, assign it to transactionFee

b)If paramater < 0.0, assign 0.0 to transactionFee.

  1. Sub Credit
  2. Overrides base class’s Credit method.
  3. Call base class’s Credit method to perform credit transaction
  4. Deduct transactionFee from balance
  5. Function Debit
  6. Overrides base class’s Debit method.
  7. Call base class’s Debit method to perform debit transaction

a)If the call returns True (successful), deduct transactionFee from balance and return True

b)If the call returns False (unsuccessful), do NOT deduct transactionFee from balance, just return False

  1. Function ToString
  2. Overrides base class’s ToString function
  3. Display transaction fee and balance (calling base class’s method)
  4. Please use the following definition in order to make testing easier.

'overrides ToString() function to display checking's information

PublicOverridesFunction ToString() AsString

Dim message AsString

message = String.Format("Transaction fee: {0:C2}", Fee) & vbCrLf

message &= MyBase.ToString()

Return message

EndFunction

  1. Add another class “SavingsAccount”inproject, which inherits from base class “Account”and includs the following members(Use the names given below):
  2. Instance variable interestRate

Doublel type, stores the inerest rate of savings account

  1. Constructor Sub New
  2. Need one Decimal parameter and one Double parameter
  3. Call base class’s constructor to set up base class part
  4. Initializes instance variable interestRate usingthe 2ndparameter’s value, if parameter < 0.0, initialize inerestRate to 0
  5. Property Rate
  6. Define Get method to return interestRate
  7. Define Set method

a)If paramater >=0.0, assign it to interestRate

b)If paramater < 0.0, assign 0.0 to interestRate

  1. Function CalculateInterest
  2. No parameter
  3. Return a decimal value
  4. interest = balance * interestRate / 12
  5. add this interest to balance
  6. return the interest
  7. Function ToString
  8. Overrides base class’s ToString function
  9. Display interest rate and interest amount, as well as balance (calling base class’s method)
  10. Please use the following definition in order to make testing easier.

'overrides ToString() function to display savingsAccount's information

PublicOverridesFunction ToString() AsString

Dim message AsString

message = String.Format("Interest rate: {0:p2}", Rate) & vbCrLf

message &= String.Format("Interest earned: {0:c2}", CalculateInterest()) & vbCrLf

message &= MyBase.ToString()

Return message

EndFunction

  1. Now, let’s test the classes, rename the file “Form1.vb” to “AccountTesterForm.vb”, create “Form_Load” event handler method, copy the following code and paste into the “Form_Load” method. Please do not modify the code in this tester in order to make testing easier.

Dim account1 AsNewSavingsAccount(25, 0.03)

Dim account2 AsNewCheckingAccount(80, 1)

' display initial balance of each object

balanceLabel.Text = "account1" & vbCrLf & Convert.ToString(account1.GetType()) & vbCrLf & account1.ToString() & vbCrLf

balanceLabel.Text &= "account2" & vbCrLf & Convert.ToString(account2.GetType()) & vbCrLf & account2.ToString() & vbCrLf

' debit each account and show new balance

balanceLabel.Text &= "Attempting to debit account1 by $20.00." & vbCrLf

If account1.Debit(20) = TrueThen

balanceLabel.Text &= account1.ToString() & vbCrLf

EndIf

balanceLabel.Text &= "Attempting to debit account2 by $40.00." & vbCrLf

If account2.Debit(40) Then

balanceLabel.Text &= account2.ToString() & vbCrLf

EndIf

' credit each account and show new balance

balanceLabel.Text &= "Crediting $40.00 to account1." & vbCrLf

account1.Credit(40)

balanceLabel.Text &= account1.ToString() & vbCrLf

balanceLabel.Text &= "Crediting $65.00 to account2." & vbCrLf

account2.Credit(65)

balanceLabel.Text &= account2.ToString()

  1. Run your project in your computer, you should get the similaroutput, If not, please debug your code and run it again.