Question: USING C# CODING LANGAUGE Please use your solution from Exercise 6 and implement Encapsulation in at least 5 places ( property , method ) within
USING C# CODING LANGAUGE
Please use your solution from Exercise and implement Encapsulation in at least places property method within your code. Afterward, provide a report explaining why you chose to apply encapsulation to those specific places.
Exercise : Bank and Bank Accounts
Create a set of classes that describe a bank and different types of bank accounts. The classes should include:
Checking Account
Savings 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 the current balance of the account.
GetTransactionCount: Tracks the number of transactions on the account.
The bank must have the following properties and methods:
A property to keep track of all its members.
A balance property, which is affected by user transactions.
The following methods for the bank:
ListAllMembersGetAccountTypeCountGetTransactionCount
Here is the base code for the system:
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 Balance;
public int GetTransactionCount 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 "Checking Account";
Savings Account class
public class SavingsAccount : BankAccount
public SavingsAccountstring accountHolderName, decimal initialBalance
: baseaccountHolderName initialBalance
public override string GetAccountType "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
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
