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 6 and implement Encapsulation in at least 5 places (property, method) within your code. Afterward, provide a report explaining why you chose to apply encapsulation to those specific places.
Exercise 6: 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 =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()=> Balance;
public int GetTransactionCount()=> 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()=> "Checking Account";
}
// Savings Account class
public class SavingsAccount : BankAccount
{
public SavingsAccount(string accountHolderName, decimal initialBalance)
: base(accountHolderName, initialBalance){}
public override string GetAccountType()=> "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

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!