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 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 changesyour 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 initialBalanceAccountId nextAccountId; AccountHolderName accountHolderName; Balance initialBalance; transactionCount ; public virtual void AddFundsdecimal amountif amount ConsoleWriteLineInvalid amount. Must be greater than zero."; return; Balance amount; transactionCount; public decimal CheckBalancereturn Balance; public int GetTransactionCountreturn transactionCount; public virtual void CloseAccountBalance ; Console.WriteLine$"Account AccountIdclosed; public abstract string GetAccountType; Checking Account class public class CheckingAccount : BankAccount public CheckingAccountstring accountHolderName, decimal initialBalance: baseaccountHolderNameinitialBalancepublic override string GetAccountTypereturn "Checking Account"; Savings Account class public class SavingsAccount : BankAccount public SavingsAccountstring accountHolderName, decimal initialBalance: baseaccountHolderNameinitialBalancepublic override string GetAccountTypereturn "Savings Account"; Bank class public class Bank public string Name get; private set; private List accounts; public Bankstring nameName name; accounts new List; public void AddAccountBankAccount accountaccountsAddaccount; public void ListAllMembersConsoleWriteLineBank Members:"; foreach var account in accountsConsoleWriteLine$"Account ID: accountAccountIdName: accountAccountHolderNameType: accountGetAccountType; public int GetAccountTypeCountstring accountTypeint count ; foreach var account in accountsif accountGetAccountTypeaccountTypecount; return count; public int GetTransactionCountint totalTransactions ; foreach var account in accountstotalTransactions accountGetTransactionCount; return totalTransactions; public decimal GetBankBalancedecimal totalBalance ; foreach var account in accountstotalBalance accountCheckBalance; return totalBalance; class Program static void MainstringargsCreate 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
