Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C#: I am getting an error on line 5 6 with the ListAccounts ( ) Constructor. Why am I getting a thrown execption. Code Below:
C#: I am getting an error on line with the ListAccounts Constructor. Why am I getting a thrown execption. Code Below: public class Bank
public string Name get; set;
public BankAccount AccountList get; set;
public int NextOpenIndex get; set;
public Bankstring bankName, int maxNumAccounts
Name bankName;
AccountList new BankAccountmaxNumAccounts;
NextOpenIndex ;
public Bankstring bankName, BankAccount bankAccounts
Name bankName;
AccountList bankAccounts;
NextOpenIndex bankAccounts.Length;
public bool AddAccountBankAccount account
if NextOpenIndex AccountList.Length && AccountList.Containsaccount
AccountListNextOpenIndex account;
NextOpenIndex;
return true;
else
Console.WriteLineCannot add account. Either the bank is full or the account already exists.";
return false;
public bool TransferBankAccount accTransferFrom, BankAccount accTransferTo, double amount
if accTransferFromBalance amount
accTransferFrom.Withdrawamount;
accTransferTo.Depositamount;
return true;
else
Console.WriteLineThere are insufficient funds in account.";
return false;
public void ListAllAccounts
Console.WriteLine$"Bank: Name;
foreach var account in AccountList
Console.WriteLine$"Account Number: accountAccountNumber Balance: accountCheckBalance;
public class BankAccount
public string AccountNumber get; set;
public double Balance get; set;
public BankAccountstring accountNumber, double initialBalance
AccountNumber accountNumber;
Balance initialBalance;
public void Depositdouble amount
Balance amount;
public bool Withdrawdouble amount
if Balance amount
Balance amount;
return true;
else
Console.WriteLine;
Console.WriteLineInsufficient funds.";
return false;
public double CheckBalance
return Balance;
class Program
static void Main
Prompt Instantiate a Bank
Bank myBank new BankMyBank;
Prompt Create Bank Accounts
BankAccount account new BankAccount;
BankAccount account new BankAccount;
BankAccount account new BankAccount;
myBank.AddAccountaccount;
myBank.AddAccountaccount;
myBank.AddAccountaccount;
Prompt Deposit Money
accountDeposit;
Prompt Withdraw Money
accountWithdraw;
Prompt Check Account Balance
Console.WriteLine$"Account Balance: accountCheckBalance;
Prompt Handle Insufficient Funds
accountWithdraw; This will display "Insufficient funds."
Prompt List All Accounts in a Bank
myBank.ListAllAccounts;
Prompt Transfer Funds Between Accounts
myBank.Transferaccount account;
Prompt Bank Capacity Check
BankAccount account new BankAccount;
BankAccount account new BankAccount;
myBank.AddAccountaccount; This will display an error message as the bank is full.
myBank.AddAccountaccount; This will display an error message as the bank is full.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started