Challenge 3: Implement a Banking Application Using Polymorphism
Explore how to implement a banking application using polymorphism in C#. Learn to define a base Account class and override its methods in SavingsAccount and CheckingAccount subclasses. Understand how to apply inheritance, method overriding, and encapsulation to manage deposits, withdrawals, and balances.
We'll cover the following...
Problem Statement
Write a code that has:
-
A base class named
Account.- Inside it define:
- A field,
private double _balance - A
protectedproperty,Balance, to access the balance public virtual bool Withdraw(double amount)public virtual bool Deposit(double amount)public virtual void PrintBalance()
- A field,
- Inside it define:
-
Then, there are two derived classes
-
SavingsAccountclass has:-
A
privatefield_interestRateset to 0.8 -
An overridden
Withdraw()method that deducts amount from balance with interestRate only if enough balance is available. The withdrawal amount should be greater than zero.- Returns
trueif the transaction was successful andfalseotherwise.
- Returns
-
An overridden
Deposit()method that adds amount to balance with interestRate and also checks if the amount to be deposited is greater than zero- Returns
trueif the transaction was successful andfalseotherwise.
- Returns
-
PrintBalance()displays the balance in the account
-
-
CheckingAccountclass has:-
An overridden
Withdraw()method that deducts amount from balance only if enough balance is available and the withdrawal amount should be greater than zero- Returns
trueif the transaction was successful andfalseotherwise.
- Returns
-
An overridden
Deposit()method that adds amount in balance and also checks if the amount to be deposited is greater than zero- Returns
trueif the transaction was successful andfalseotherwise.
- Returns
-
PrintBalance()displays the balance in the account
-
-
For SavingsAccount:
...