Question: C# I need to make a program that follows the given prompts: ### Prompt 1 - Instantiate a Bank Write a code snippet to create

C# I need to make a program that follows the given prompts: ### Prompt 1- Instantiate a Bank
Write a code snippet to create an instance of a `Bank` with a specified name and maximum number of accounts.
### Prompt 2- Create Bank Accounts
Instantiate several `BankAccount` objects with different account numbers and associate them with the bank instance created in prompt 1.
### Prompt 3- Deposit Money
Write a method to deposit a certain amount of money into one of the `BankAccount` instances.
### Prompt 4- Withdraw Money
Implement a code snippet to withdraw an amount from a `BankAccount`. Check if the withdrawal is successful.
### Prompt 5- Check Account Balance
Display the balance of a specific `BankAccount` after performing deposit and withdrawal operations.
### Prompt 6- Handle Insufficient Funds
Attempt a withdrawal that exceeds the account balance and handle the `-1` that is returned by displaying an appropriate message.
### Prompt 7- List All Accounts in a Bank
Loop through all accounts in a bank and display their details (account number and balance).
### Prompt 8- Transfer Funds Between Accounts
Transfer funds from one account to another within the same bank. ### Prompt 9- Bank Capacity Check
Try adding more `BankAccount` instances to the bank than its maximum capacity allows and handle the error gracefully. This is the code I have now, but I am getting an error saying : An unhandled exception of type 'System.NullReferenceException' occurred in Bank.dll: 'Object reference npublic class Bank
{
public string Name { get; set; }
public BankAccount[] AccountList { get; set; }
public int NextOpenIndex { get; set; }
public Bank(string bankName, int maxNumAccounts)
{
Name = bankName;
AccountList = new BankAccount[maxNumAccounts];
NextOpenIndex =0;
}
public Bank(string bankName, BankAccount[] bankAccounts)
{
Name = bankName;
AccountList = bankAccounts;
NextOpenIndex = bankAccounts.Length;
}
public bool AddAccount(BankAccount account)
{
if (NextOpenIndex < AccountList.Length && !AccountList.Contains(account))
{
AccountList[NextOpenIndex]= account;
NextOpenIndex++;
return true;
}
else
{
Console.WriteLine("Cannot add account. Either the bank is full or the account already exists.");
return false;
}
}
public bool Transfer(BankAccount accTransferFrom, BankAccount accTransferTo, double amount)
{
if (accTransferFrom.Balance >= amount)
{
accTransferFrom.Withdraw(amount);
accTransferTo.Deposit(amount);
return true;
}
else
{
Console.WriteLine("There are insufficient funds in account.");
return false;
}
}
public void ListAllAccounts()
{
Console.WriteLine($"Bank: {Name}");
foreach (var account in AccountList)
{
Console.WriteLine($"Account Number: {account.AccountNumber}, Balance: {account.CheckBalance()}");
}
}
}
public class BankAccount
{
public string AccountNumber { get; set; }
public double Balance { get; set; }
public BankAccount(string accountNumber, double initialBalance)
{
AccountNumber = accountNumber;
Balance = initialBalance;
}
public void Deposit(double amount)
{
Balance += amount;
}
public bool Withdraw(double amount)
{
if (Balance >= amount)
{
Balance -= amount;
return true;
}
else
{
Console.WriteLine("Insufficient funds.");
return false;
}
}
public double CheckBalance()
{
return Balance;
}
}
class Program
{
static void Main()
{
// Prompt 1- Instantiate a Bank
Bank myBank = new Bank("MyBank",5);
// Prompt 2- Create Bank Accounts
BankAccount account1= new BankAccount("001",1000);
BankAccount account2= new BankAccount("002",500);
BankAccount account3= new BankAccount("003",1500);
myBank.AddAccount(account1);
myBank.AddAccount(account2);
myBank.AddAccount(account3);
// Prompt 3- Deposit Money
account1.Deposit(200);
// Prompt 4- Withdraw Money
account2.Withdraw(100);
// Prompt 5- Check Account Balance
Console.WriteLine($"Account1 Balance: {account1.CheckBalance()}");
// Prompt 6- Handle Insufficient Funds
account3.Withdraw(2000); // This willot set to an instance of an object.'

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 Databases Questions!