Lab Exercise 4 Instruction
Lab Exercise 4 Instruction
Objectives:
1. Apply object-oriented concepts to design an object-oriented system.
2. Understand the Universal Modeling Language (UML).
3. Understand class-inheritance relationship required to develop an object-oriented system.
4. Read class diagrams to build classes that represent user defined data types.
Preamble:
The ‘Bank of OOP’ needs programs to automate their operations. To operate their bank machines a set of classes are needed to
represent the business logic of bank accounts.
The following base class is common code to all the derived bank account classes:
• Bank Account:
o Account number and client name are required. Base class includes date opened, balance, and bank name – all are read
only. When an account is created the date opened field defaults to current date.
o Overrides the ToString method. Returns a string containing all fields formatted.
o Deposit method with deposit amount passed in as a parameter – must be positive. The method returns the balance.
o Virtual WithDraw method withdrawal amount passed in as a parameter – must be positive and greater or equal to the
balance. If the with draw is successful, the withdraw amount is assigned to an out variable. The out funds variable is set
to zero for insufficient funds. The method returns the UpToDate balance.
The bank offers the following accounts:
• Saving Accounts:
o Offers a default 4% interest rate – which can be set: 1% to 20%
o Interest is applied by an ApplyMonthlyInterest method which adds the interest to the balance and returns the amount of
interest applied.
o Charge $0.50 for each withdrawal – the Withdraw method withdraws a positive amount plus 50 cents from the balance
and returns the UpToDate balance. The out funds are set to zero or the successful withdraw amount – the amount
withdrawn plus withdraw charge cannot exceed the balance.
• Chequing accounts:
o Pay no interest.
o Have a default monthly service fee of $10.00 – which can be set: minimum $10 and no maximum
o Monthly charges are applied by a virtual ApplyMonthlyFee method which subtracts the fee from the balance and returns
the amount subtracted (the fee)
o No fees are applied to withdrawals so the base class version is inherited as is
• Premium Accounts:
o Work the same as regular chequing accounts but offer an overdraft limit of $100 – which can be set: minimum $100 and
no maximum.
o Customers pay an additional 2-dollar fee each month for the overdraft. This fee is applied by the ApplyMonthlyFee
method which subtracts the base fee from the chequing account with an additional $2 from the balance and returns the
amount subtracted (the fee + $2)
o No fees are applied to withdrawals except when in overdraft mode (balance is less than zero). A 2% charge is applied to
the amount of overdraft withdrawn from the account. For example: If the customer withdraws $100 from a balance of
$50, the amount of overdraft is $50 (-$50). 2% of the overdraft amount (50*0.02 = $1) is also withdrawn from the
balance. The balance cannot exceed the overdraft amount plus charge and the amount withdrawn cannot be negative.
The method returns the UpToDate balance. The out funds are set to zero or to the successful withdraw amount.
Instructions:
Develop a class hierarchy of bank accounts. Examine the following UML design of four classes: BankAccount, SavingsAccount,
ChequingAccount, and PremiumAccount. Create these classes based on the Class design and the requirements listed above. Add
validation and/or exception handling code.
Console Application: Create a new Console Application (.Net Framework) named Lab4. Add 4 separate files to this project for each
of the four classes. Write the code required in each class.
Inside the main method…Declare one of each type of account and test the properties and methods. Hard-code example values for
the properties. Display bank account information. Show the balance before and after deposits and withdraws. Format the console
output.
Show your completed solution to your instructor in the Lab by the due date posted in Brightspace.
PROG1224 Lab Exercise 4
Class Relationships:
BackAccount
SavingsAccount ChequingAccount
PremiumAccount
BankAccount
- accNumber : int
- name : string
- open : DateTime
# balance : decimal
+ BankName : string
+ AccountNumber : int
+ Name : string
+ DateOpen : string
+ Balance : string
+ BankAccount(accountNumber : int, startBalance : decimal, nameOfClient : string)
+ ToString( ) : string
+ Deposit(amount : decimal) : decimal
+ WithDraw(amount : decimal, funds : decimal) : decimal
SavingsAccount
- interest : decimal
+ Interest : decimal
+ SavingAccount(accountNumber : int, startBalance : decimal, nameOfClient : string, interest : decimal)
+ ApplyMonthlyInterest() : decimal
+ WithDraw(amount : decimal, funds : decimal) : decimal
ChequingAccount
- fee : decimal
+ Fee : decimal
+ ChequingAccount(accountNumber : int, startBalance : decimal, nameOfClient : string, fee : decimal)
+ ApplyMonthlyFee() : decimal
PremiumAccount
- over : decimal
+ OverDraft : decimal
+ PremiumAccount(accountNumber : int, startBalance : decimal, nameOfClient : string, fee : decimal, overdraft : decimal)
+ ApplyMonthlyFee( ) : decimal
+ WithDraw(amount : decimal, funds : decimal) : decimal
Show your completed solution to your instructor in the Lab by the due date posted in Brightspace.