Question: USING C# Use your exercise 6 implementation . Add PrintBalance method to your Account class Create two new classes: CheckingAccount must inherit from Account classSavingsAccount

USING C#
Use your exercise 6implementation.
Add "PrintBalance" method to your Account class
Create two new classes:
CheckingAccount must inherit from Account classSavingsAccount must inherit from Account class
You must re-factor (make necessary changes)your code to use the new classes.
Exersize 6: 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 =1; public int AccountId {get; private set; }public string AccountHolderName {get; private set; }protected decimal Balance {get; set; }private int transactionCount; protected BankAccount(string accountHolderName, decimal initialBalance){AccountId =nextAccountId++; AccountHolderName =accountHolderName; Balance =initialBalance; transactionCount =0; }public virtual void AddFunds(decimal amount){if (amount <=0){Console.WriteLine("Invalid 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 =0; Console.WriteLine($"Account {AccountId}closed."); }public abstract string GetAccountType(); }//Checking Account class public class CheckingAccount : BankAccount {public CheckingAccount(string accountHolderName, decimal initialBalance): base(accountHolderName,initialBalance){}public override string GetAccountType(){return "Checking Account"; }}//Savings Account class public class SavingsAccount : BankAccount {public SavingsAccount(string accountHolderName, decimal initialBalance): base(accountHolderName,initialBalance){}public override string GetAccountType(){return "Savings Account"; }}//Bank class public class Bank {public string Name {get; private set; }private List accounts; public Bank(string name){Name =name; accounts =new List(); }public void AddAccount(BankAccount account){accounts.Add(account); }public void ListAllMembers(){Console.WriteLine("Bank Members:"); foreach (var account in accounts){Console.WriteLine($"Account ID: {account.AccountId},Name: {account.AccountHolderName},Type: {account.GetAccountType()}"); }}public int GetAccountTypeCount(string accountType){int count =0; foreach (var account in accounts){if (account.GetAccountType()==accountType)count++; }return count; }public int GetTransactionCount(){int totalTransactions =0; foreach (var account in accounts){totalTransactions +=account.GetTransactionCount(); }return totalTransactions; }public decimal GetBankBalance(){decimal totalBalance =0; foreach (var account in accounts){totalBalance +=account.CheckBalance(); }return totalBalance; }}class Program {static void Main(string[]args){//Create a bank Bank bank =new Bank("My Bank"); //Create accounts var checkingAccount =new CheckingAccount("Alice",1000); var savingsAccount =new SavingsAccount("Bob",2000); //Add accounts to the bank bank.AddAccount(checkingAccount); bank.AddAccount(savingsAccount); //Perform some operations checkingAccount.AddFunds(500); savingsAccount.AddFunds(1000); Console.WriteLine($"Total Bank Balance: {bank.GetBankBalance()}"); Console.WriteLine($"Total Transactions: {bank.GetTransactionCount()}"); bank.ListAllMembers(); Console.WriteLine($"Number of Checking Accounts: {bank.GetAccountTypeCount("Checking Account")}"); Console.WriteLine($"Number of Savings Accounts: {bank.GetAccountTypeCount("Savings Account")}"); }}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!