Question: Use your exercise 6 implementation. Add PrintBalance method to your Account class Create two new classes: CheckingAccount must inherit from Account classSavingsAccount must inherit from
Use your exercise implementation.
Add "PrintBalance" method to your Account class
Create two new classes:
CheckingAccount must inherit from Account classSavingsAccount must inherit from Account class
You must refactor make necessary changes your code to use the new classes.
Exersize : Create a set of classes that describe a bank and the different types of bank accounts:
Checking AccountSavings Account
Add the following methods to each bank account:
CloseAccount: Used when a bank account must be closed.AddFunds: Used when we need to add funds to the account.CheckBalance: Used when we need to check current balance on account.GetTransactionCount: You must keep track of the # of transactions on the account.
The bank must have a property that keeps track of all its members
The bank must have a balance, which is affected based on user transactions
The bank must have the following methods:
ListAllMemebersGetAccountTypeCountGetTransactionCount
using System; using System.Collections.Generic; namespace BankApplication Base class for Bank Account public abstract class BankAccount private static int nextAccountId ; public int AccountId get; private set; public string AccountHolderName get; private set; protected decimal Balance get; set; private int transactionCount; protected BankAccountstring accountHolderName, decimal initialBalance AccountId nextAccountId; AccountHolderName accountHolderName; Balance initialBalance; transactionCount ; public virtual void AddFundsdecimal amount if amount Console.WriteLineInvalid amount. Must be greater than zero."; return; Balance amount; transactionCount; public decimal CheckBalance return Balance; public int GetTransactionCount return transactionCount; public virtual void CloseAccount Balance ; Console.WriteLine$"Account AccountId closed."; public abstract string GetAccountType; Checking Account class public class CheckingAccount : BankAccount public CheckingAccountstring accountHolderName, decimal initialBalance : baseaccountHolderName initialBalance public override string GetAccountType return "Checking Account"; Savings Account class public class SavingsAccount : BankAccount public SavingsAccountstring accountHolderName, decimal initialBalance : baseaccountHolderName initialBalance public override string GetAccountType return "Savings Account"; Bank class public class Bank public string Name get; private set; private List accounts; public Bankstring name Name name; accounts new List; public void AddAccountBankAccount account accounts.Addaccount; public void ListAllMembers Console.WriteLineBank Members:"; foreach var account in accounts Console.WriteLine$"Account ID: accountAccountId Name: accountAccountHolderName Type: accountGetAccountType; public int GetAccountTypeCountstring accountType int count ; foreach var account in accounts if accountGetAccountType accountType count; return count; public int GetTransactionCount int totalTransactions ; foreach var account in accounts totalTransactions account.GetTransactionCount; return totalTransactions; public decimal GetBankBalance decimal totalBalance ; foreach var account in accounts totalBalance account.CheckBalance; return totalBalance; class Program static void Mainstring args Create a bank Bank bank new BankMy Bank"; Create accounts var checkingAccount new CheckingAccountAlice; var savingsAccount new SavingsAccountBob; Add accounts to the bank bank.AddAccountcheckingAccount; bank.AddAccountsavingsAccount; Perform some operations checkingAccount.AddFunds; savingsAccount.AddFunds; Console.WriteLine$"Total Bank Balance: bankGetBankBalance; Console.WriteLine$"Total Transactions: bankGetTransactionCount; bank.ListAllMembers; Console.WriteLine$"Number of Checking Accounts: bankGetAccountTypeCountChecking Account"; Console.WriteLine$"Number of Savings Accounts: bankGetAccountTypeCountSavings Account";
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
