in C# Create a Bank class with the following properties: List of bank accounts (List) Create the following methods in the Bank class: AddAccount(BankAccount account): Method to add a new bank account to the list of accounts RemoveAccount(string accountNumber): Method to remove an existing bank account from the list of accounts SearchAccount(string accountNumber): Method to search for an existing bank account and return the account details my code is  // This class represents a bank, which has a list of BankAccount objects as one of its properties. public class Bank {     // This property holds a list of BankAccount objects belonging to the bank.     public List Accounts { get; set; }     // This constructor initializes the list of accounts for the bank.     public Bank()     {         Accounts = new List();     }     // This method adds a new BankAccount object to the bank's list of accounts.     public void AddAccount(BankAccount account)     {         Accounts.Add(account);     }     // This method removes a BankAccount object with the given account number from the bank's list of accounts.     // It returns true if the account was found and removed, and false otherwise.     public bool RemoveAccount(string accountNumber)     {         // Find the BankAccount object with the given account number.         BankAccount accountToRemove = Accounts.Find(account => account.AccountNumber == accountNumber);                 // If such an account was found, remove it from the list and return true.         if (accountToRemove != null)         {             Accounts.Remove(accountToRemove);             return true;         }                 // If no account was found, return false.         return false;     }     // This method searches for a BankAccount object with the given account number in the bank's list of accounts.     // It returns the BankAccount object if found, and null otherwise.     public BankAccount SearchAccount(string accountNumber)     {         // Find the BankAccount object with the given account number.         BankAccount account = Accounts.Find(account => account.AccountNumber == accountNumber);                 // Return the found account, or null if no account was found.         return account;     } } my errors are in the pic

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Question

in C#

  • Create a Bank class with the following properties:

    • List of bank accounts (List<BankAccount>)
  • Create the following methods in the Bank class:

    • AddAccount(BankAccount account): Method to add a new bank account to the list of accounts
    • RemoveAccount(string accountNumber): Method to remove an existing bank account from the list of accounts
    • SearchAccount(string accountNumber): Method to search for an existing bank account and return the account details

my code is 


// This class represents a bank, which has a list of BankAccount objects as one of its properties.
public class Bank
{
    // This property holds a list of BankAccount objects belonging to the bank.
    public List<BankAccount> Accounts { get; set; }

    // This constructor initializes the list of accounts for the bank.
    public Bank()
    {
        Accounts = new List<BankAccount>();
    }

    // This method adds a new BankAccount object to the bank's list of accounts.
    public void AddAccount(BankAccount account)
    {
        Accounts.Add(account);
    }

    // This method removes a BankAccount object with the given account number from the bank's list of accounts.
    // It returns true if the account was found and removed, and false otherwise.
    public bool RemoveAccount(string accountNumber)
    {
        // Find the BankAccount object with the given account number.
        BankAccount accountToRemove = Accounts.Find(account => account.AccountNumber == accountNumber);
       
        // If such an account was found, remove it from the list and return true.
        if (accountToRemove != null)
        {
            Accounts.Remove(accountToRemove);
            return true;
        }
       
        // If no account was found, return false.
        return false;
    }

    // This method searches for a BankAccount object with the given account number in the bank's list of accounts.
    // It returns the BankAccount object if found, and null otherwise.
    public BankAccount SearchAccount(string accountNumber)
    {
        // Find the BankAccount object with the given account number.
        BankAccount account = Accounts.Find(account => account.AccountNumber == accountNumber);
       
        // Return the found account, or null if no account was found.
        return account;
    }
}
my errors are in the pic
PS E:\stef C# homework\New folder> dotnet "C:\Users\stefa\AppData\Roaming\Code\User\cs-script.user\dotnet\cscs.dll" "e:\stef C# homework\New folder\Bank.cs"
Error: Specified file could not be compiled.
e:\stef C# homework\New folder\Bank.cs(6,12):
embly reference?)
error CS0246: The type or namespace name 'List<>' could not be found (are you missing a using directive or an ass
e:\stef C# homework\New folder\Bank.cs(6,17): error CS0246: The type or namespace name 'BankAccount' could not be found (are you missing a using directive or a
n assembly reference?)
e:\stef C# homework\New folder\Bank.cs (15,28): error CS0246: The type or namespace name 'BankAccount' could not be found (are you missing a using directive or
an assembly reference?)
e:\stef C# homework\New folder\Bank.cs (40,12): error CS0246: The type or namespace name 'BankAccount' could not be found (are you missing a using directive or
an assembly reference?)
e:\stef C# homework\New folder\Bank.cs(6,12): error CS0246: The type or namespace name 'List<>' could not be found (are you missing a using directive or an ass
embly reference?)
e:\stef C# homework\New folder\Bank.cs(6,17): error CS0246:
n assembly reference?)
e:\stef C# homework\New folder\Bank.cs (15,28): error CS0246:
an assembly reference?)
The type or namespace name 'BankAccount' could not be found (are you missing a using directive or a
The type or namespace name 'BankAccount' could not be found (are you missing a using directive or
The type or namespace name 'BankAccount' could not be found (are you missing a using directive or
e:\stef C# homework\New folder\Bank.cs (40,12): error CS0246:
an assembly reference?)
PS E:\stef C# homework\New folder>
Transcribed Image Text:PS E:\stef C# homework\New folder> dotnet "C:\Users\stefa\AppData\Roaming\Code\User\cs-script.user\dotnet\cscs.dll" "e:\stef C# homework\New folder\Bank.cs" Error: Specified file could not be compiled. e:\stef C# homework\New folder\Bank.cs(6,12): embly reference?) error CS0246: The type or namespace name 'List<>' could not be found (are you missing a using directive or an ass e:\stef C# homework\New folder\Bank.cs(6,17): error CS0246: The type or namespace name 'BankAccount' could not be found (are you missing a using directive or a n assembly reference?) e:\stef C# homework\New folder\Bank.cs (15,28): error CS0246: The type or namespace name 'BankAccount' could not be found (are you missing a using directive or an assembly reference?) e:\stef C# homework\New folder\Bank.cs (40,12): error CS0246: The type or namespace name 'BankAccount' could not be found (are you missing a using directive or an assembly reference?) e:\stef C# homework\New folder\Bank.cs(6,12): error CS0246: The type or namespace name 'List<>' could not be found (are you missing a using directive or an ass embly reference?) e:\stef C# homework\New folder\Bank.cs(6,17): error CS0246: n assembly reference?) e:\stef C# homework\New folder\Bank.cs (15,28): error CS0246: an assembly reference?) The type or namespace name 'BankAccount' could not be found (are you missing a using directive or a The type or namespace name 'BankAccount' could not be found (are you missing a using directive or The type or namespace name 'BankAccount' could not be found (are you missing a using directive or e:\stef C# homework\New folder\Bank.cs (40,12): error CS0246: an assembly reference?) PS E:\stef C# homework\New folder>
Expert Solution
Step 1

Solution:

 

Given,

 

These errors indicate that the compiler is unable to find the definition for the List<> and BankAccount types. You need to make sure that you have the necessary using directives and references in your code.

Make sure that you have added the following using directives at the top of your file:

using System.Collections.Generic;

Remark:

Also, make sure that you have a separate file for the BankAccount class, and that it is defined in the same namespace as the Bank class. If the BankAccount class is defined in a different namespace, you will need to add a using directive for that namespace as well.

If you have done these things correctly and are still getting the errors, you may need to check that the file paths and project references in your Visual Studio solution are set up correctly.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education