Programming Language: C#
CheckingAccount class
You will implement the CheckingAccount Class in Visual Studio.This is a sub class is derived from the Account class andimplements the ITransaction interface. There are two classvariables i.e. variables that are shared but all the objects ofthis class. A short description of the class members is givenbelow:
CheckingAccount Class |
Fields |
$- COST_PER_TRANSACTION = 0.05 :double $- INTEREST_RATE = 0.005 :double - hasOverdraft:bool |
Methods |
+ «Constructor»CheckingAccount(balance = 0 : double, hasOverdraft= false: bool) + Deposit(amount :double, person : Person) :void + Withdraw(amount :double, person : Person) :void + PrepareMonthlyReport(amount :double, person : Person) :void |
Fields:
- COST_PER_TRANSACTION – this is a classvariable of type double representing the unit cost per transaction.All of the objects on this class will have the same value. Thisclass variable is initialized to 0.05.
- INTEREST_RATE – this is a class variable oftype double representing the annual interest rate. All of theobjects on this class will have the same value. This class variableis initialized to 0.005.
- hasOverdraft – this is a bool indicating ifthe balance on this account can be less than zero. This privateinstance variable is set in the constructor.
Methods:
- public CheckingAccount(double balance = 0,bool hasOverdraft =false ) – This public constructortakes a parameter of type double representing the starting balanceof the account and a bool indicating if this account has over draftpermission. The constructor does the following:
- It invokes the base constructor with the string “CK-†and theappropriate argument.
- Assigns the hasOverdraft argument to the appropriatefield.
This definition hides the corresponding member in the parentclass because the base class implementation is needed for thismethod as well as the Withdraw() method |
public new void Deposit(double amount,Person person ) – this publicmethod takes two arguments: a double representing the amount to bedeposited and a person object representing the person do thetransaction. The method does the following:- Calls the Deposit() method of the base classwith the appropriate arguments
- public voidWithdraw( doubleamount, Person person) – this public method takes two arguments: a doublerepresenting the amount to be withdrawn and a person objectrepresenting the person do the transaction. The method does thefollowing:
- Throws an AccountException object if thisperson in not associated with this account.
- Throws an AccountException object if thisperson in not logged in.
- Throws an AccountException object if thewithdrawal amount is greater than the balance and there is nooverdraft facility.
- Otherwise it calls the Deposit() method of thebase class with the appropriate arguments (you will send negativeof the amount)
- public overridevoid PrepareMonthlyReport( ) –this public method override the method of the base class with thesame name. The method does the following:
- Calculate the service charge by multiplying the number oftransactions by the COST_PER_TRANSACTION (how canyou find out the number of transactions?)
- Calculate the interest by multiplying theLowestBalance by theINTEREST_RATE and then dividing by 12
- Update the Balance by adding the interest andsubtracting the service charge
In a real-world application, the transaction objects would bearchived before clearing. |
transactions is re-initialized (use theClear() method of the list class)
This method does not take anyparameter nor does it display anything
SavingAccount class
You will implement the SavingAccount Class in Visual Studio.This is a sub class derived from the Account classand implements the ITransaction interface. Again,there are two class variables. A short description of the classmembers is given below:
SavingAccount Class → Account, ITransaction |
Fields |
$- COST_PER_TRANSACTION :double $- INTEREST_RATE :double |
Methods |
+ «Constructor» SavingAccount(balance= 0 : double) + Deposit(amount :double, person : Person) :void + Withdraw(amount :double, person : Person) :void + PrepareMonthlyReport(amount :double, person : Person) :void |
Fields:
- COST_PER_TRANSACTION – this is a classvariable of type double representing the unit cost per transaction.All of the objects on this class will have the same value. Thisclass variable is initialized to 0.05.
- INTEREST_RATE – this is a class variable oftype double representing the annual interest rate. All of theobjects on this class will have the same value. This class variableis initialized to 0.015.
Methods:
- public SavingAccount(double balance = 0 ) – Thispublic constructor takes a parameter of type double representingthe starting balance of the account. The constructor does thefollowing:
- It invokes the base constructor with the string “SV-†and itsargument.
- public new void Deposit(double amount,Person person ) – this publicmethod takes two arguments: a double representing the amount to bedeposited and a person object representing the person do thetransaction. The method calls the Deposit() methodof the base class with the appropriate arguments.
- public voidWithdraw( doubleamount, Person person) – this public method takes two arguments: a doublerepresenting the amount to be withdrawn and a person objectrepresenting the person do the transaction. The method does thefollowing:
- Throws an AccountException object if thisperson in not associated with this account.
- Throws an AccountException object if thisperson in not logged in.
- Throws an AccountException object if theintended withdrawal amount exceeds the balance.
- Otherwise it calls the Deposit() method of thebase class with the appropriate arguments (you will send negativeof the amount)
- public overridevoid PrepareMonthlyReport( ) –this public method override the method of the base class with thesame name. The method does the following:
- Calculate the service charge by multiplying the number oftransactions by the COST_PER_TRANSACTION (how canyou find out the number of transactions?)
- Calculate the interest by multiplying theLowestBalance by theINTEREST_RATE and then dividing by 12
- Update the Balance by adding the interest andsubtracting the service charge
- transactions is re-initialized (use theClear() method of the list class)
This method does not take any parameters, nor does it displayanything