Description of this paper

10-1 Create an object inheritance hierarchy

Description

solution


Question

;;Create an object inheritance hierarchy that a bank might use to represent customer?s bank accounts. Here are the specifications;Class hierarchy;Create a Windows Form project.;Add a Class ?Account? (base class)anddefine the following members (Use the names given below);Instance variable balanceValue;Decimal type, stores the account balance;Constructor Sub New;Need one Decimal parameter, initialize instance variable balanceValue using the parameter;Property Balance;i. Define Get method to return balanceValue;ii. Define Set method;a) If paramater >=0.0, assign it to balanceValue;b) If paramater balanceValue, then just return False.;v. If parameter <= balanceValue, deduct parameter value from balanceValue and return True.;Function ToString;i. Overrides Object?s ToString function;ii. Display account?s balance;iii. Please use the following definition in order to make testing easier.;overrides ToString() to display account's information;Public Overrides Function ToString() As String;Return (String.Format("Balance: {0:C2}", Balance) & vbCrLf);End Function;Add Class ?CheckingAccount? in the project, which inherits from class Account and includes the following members (Use the names given below);Instance variable transactionFee;Decimal type, stores the fee chared per transaction;Constructor Sub New;i. Need two Decimal parameter;ii. Call base class?s constructor to set up base class part;iii. Initializes instance variable transactionFee using parameter?s value, if parameter =0.0, assign it to transactionFee;b) If paramater < 0.0, assign 0.0 to transactionFee.;Sub Credit;i. Overrides base class?s Credit method.;ii. Call base class?s Credit method to perform credit transaction;iii. Deduct transactionFee from balance;Function Debit;i. Overrides base class?s Debit method.;ii. 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;Function ToString;i. Overrides base class?s ToString function;ii. Display transaction fee and balance (calling base class?s method);iii. Please use the following definition in order to make testing easier.;overrides ToString() function to display checking's information;Public Overrides Function ToString() As String;Dim message As String;message = String.Format("Transaction fee: {0:C2}", Fee) & vbCrLf;message &= MyBase.ToString();Return message;End Function;Add another class ?SavingsAccount? inproject, which inherits from base class ?Account? and includs the following members (Use the names given below);Instance variable interestRate;Doublel type, stores the inerest rate of savings account;Constructor Sub New;i. Need one Decimal parameter and one Double parameter;ii. Call base class?s constructor to set up base class part;iii. Initializes instance variable interestRate using the 2 nd parameter?s value, if parameter =0.0, assign it to interestRate;b) If paramater < 0.0, assign 0.0 to interestRate;Function CalculateInterest;i. No parameter;ii. Return a decimal value;iii. interest = balance * interestRate / 12;iv. add this interest to balance;v. return the interest;Function ToString;i. Overrides base class?s ToString function;ii. Display interest rate and interest amount, as well as balance (calling base class?s method);iii. Please use the following definition in order to make testing easier.;overrides ToString() function to display savingsAccount's information;Public Overrides Function ToString() As String;Dim message As String;message = String.Format("Interest rate: {0:p2}", Rate) & vbCrLf;message &= String.Format("Interest earned: {0:c2}", CalculateInterest()) & vbCrLf;message &= MyBase.ToString();Return message;End Function;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.;BalanceLabel

 

Paper#67130 | Written in 18-Jul-2015

Price : $32
SiteLock