in C# errors are in pics class Program { static void Main(string[] args) { Bank myBank = new Bank(); // Adding bank accounts BankAccount account1 = new BankAccount { AccountNumber = "001", AccountHolderName = "John Doe", Balance = 5000, AccountType = AccountType.Savings }; myBank.AddAccount(account1); BankAccount account2 = new BankAccount { AccountNumber = "002", AccountHolderName = "Jane Smith", Balance = 10000, AccountType = AccountType.Current }; myBank.AddAccount(account2); BankAccount account3 = new BankAccount { AccountNumber = "003", AccountHolderName = "Bob Johnson", Balance = 7500, AccountType = AccountType.Savings }; myBank.AddAccount(account3); // Searching for an existing account and displaying its details Console.WriteLine("Enter the account number to search: "); string accountNumber = Console.ReadLine(); BankAccount foundAccount = myBank.SearchAccount(accountNumber); if (foundAccount != null) { Console.WriteLine($"Account Number: {foundAccount.AccountNumber}"); Console.WriteLine($"Account Holder Name: {foundAccount.AccountHolderName}"); Console.WriteLine($"Account Type: {foundAccount.AccountType}"); Console.WriteLine($"Balance: {foundAccount.CheckBalance()}"); } else { Console.WriteLine("Account not found."); } // Depositing an amount into an account Console.WriteLine("Enter the account number to deposit into: "); accountNumber = Console.ReadLine(); foundAccount = myBank.SearchAccount(accountNumber); if (foundAccount != null) { Console.WriteLine("Enter the amount to deposit: "); double amount; while (!double.TryParse(Console.ReadLine(), out amount)) { Console.WriteLine("Invalid input. Please enter a number."); } foundAccount.Deposit(amount); Console.WriteLine($"Deposit successful. New balance: {foundAccount.CheckBalance()}"); } else { Console.WriteLine("Account not found."); } // Withdrawing an amount from an account Console.WriteLine("Enter the account number to withdraw from: "); accountNumber = Console.ReadLine(); foundAccount = myBank.SearchAccount(accountNumber); if (foundAccount != null) { Console.WriteLine("Enter the amount to withdraw: "); double amount; while (!double.TryParse(Console.ReadLine(), out amount)) { Console.WriteLine("Invalid input. Please enter a number."); } if (foundAccount.Withdraw(amount)) { Console.WriteLine($"Withdrawal successful. New balance: {foundAccount.CheckBalance()}"); } else { Console.WriteLine("Insufficient balance."); } } else { Console.WriteLine("Account not found."); } // Searching for the account again and displaying the updated account details Console.WriteLine("Enter the account number to search: "); accountNumber = Console.ReadLine(); foundAccount = myBank.SearchAccount(accountNumber); if (foundAccount != null) { Console.WriteLine($"Account Number: {foundAccount.AccountNumber}"); Console.WriteLine($"Account Holder Name: {foundAccount.AccountHolderName}"); Console.WriteLine($"Account Type: {foundAccount.AccountType}"); Console.WriteLine($"Balance: {foundAccount.CheckBalance()}"); } else { Console.WriteLine("Account not found."); } // Removing an account Console.WriteLine("Enter the account number to remove: "); accountNumber = Console.ReadLine(); bool isRemoved = myBank.RemoveAccount(accountNumber); if (isRemoved) { Console.WriteLine("Account removed successfully."); } else { Console.WriteLine("Account not found."); } // Testing additional functionality // Input validation for adding an account BankAccount account4 = new BankAccount { AccountNumber = "004", AccountHolderName = "Invalid Name", Balance = -1000, AccountType = (AccountType)99 }; myBank.AddAccount(account4); // Input validation for depositing into an account foundAccount = myBank.SearchAccount("002"); foundAccount.Deposit(-500); // Input validation for withdrawing from an account foundAccount = myBank.SearchAccount("003"); foundAccount.Withdraw(10000); // Input validation for searching an account foundAccount = myBank.SearchAccount("1000"); Console.ReadLine(); } }
in C# errors are in pics class Program { static void Main(string[] args) { Bank myBank = new Bank(); // Adding bank accounts BankAccount account1 = new BankAccount { AccountNumber = "001", AccountHolderName = "John Doe", Balance = 5000, AccountType = AccountType.Savings }; myBank.AddAccount(account1); BankAccount account2 = new BankAccount { AccountNumber = "002", AccountHolderName = "Jane Smith", Balance = 10000, AccountType = AccountType.Current }; myBank.AddAccount(account2); BankAccount account3 = new BankAccount { AccountNumber = "003", AccountHolderName = "Bob Johnson", Balance = 7500, AccountType = AccountType.Savings }; myBank.AddAccount(account3); // Searching for an existing account and displaying its details Console.WriteLine("Enter the account number to search: "); string accountNumber = Console.ReadLine(); BankAccount foundAccount = myBank.SearchAccount(accountNumber); if (foundAccount != null) { Console.WriteLine($"Account Number: {foundAccount.AccountNumber}"); Console.WriteLine($"Account Holder Name: {foundAccount.AccountHolderName}"); Console.WriteLine($"Account Type: {foundAccount.AccountType}"); Console.WriteLine($"Balance: {foundAccount.CheckBalance()}"); } else { Console.WriteLine("Account not found."); } // Depositing an amount into an account Console.WriteLine("Enter the account number to deposit into: "); accountNumber = Console.ReadLine(); foundAccount = myBank.SearchAccount(accountNumber); if (foundAccount != null) { Console.WriteLine("Enter the amount to deposit: "); double amount; while (!double.TryParse(Console.ReadLine(), out amount)) { Console.WriteLine("Invalid input. Please enter a number."); } foundAccount.Deposit(amount); Console.WriteLine($"Deposit successful. New balance: {foundAccount.CheckBalance()}"); } else { Console.WriteLine("Account not found."); } // Withdrawing an amount from an account Console.WriteLine("Enter the account number to withdraw from: "); accountNumber = Console.ReadLine(); foundAccount = myBank.SearchAccount(accountNumber); if (foundAccount != null) { Console.WriteLine("Enter the amount to withdraw: "); double amount; while (!double.TryParse(Console.ReadLine(), out amount)) { Console.WriteLine("Invalid input. Please enter a number."); } if (foundAccount.Withdraw(amount)) { Console.WriteLine($"Withdrawal successful. New balance: {foundAccount.CheckBalance()}"); } else { Console.WriteLine("Insufficient balance."); } } else { Console.WriteLine("Account not found."); } // Searching for the account again and displaying the updated account details Console.WriteLine("Enter the account number to search: "); accountNumber = Console.ReadLine(); foundAccount = myBank.SearchAccount(accountNumber); if (foundAccount != null) { Console.WriteLine($"Account Number: {foundAccount.AccountNumber}"); Console.WriteLine($"Account Holder Name: {foundAccount.AccountHolderName}"); Console.WriteLine($"Account Type: {foundAccount.AccountType}"); Console.WriteLine($"Balance: {foundAccount.CheckBalance()}"); } else { Console.WriteLine("Account not found."); } // Removing an account Console.WriteLine("Enter the account number to remove: "); accountNumber = Console.ReadLine(); bool isRemoved = myBank.RemoveAccount(accountNumber); if (isRemoved) { Console.WriteLine("Account removed successfully."); } else { Console.WriteLine("Account not found."); } // Testing additional functionality // Input validation for adding an account BankAccount account4 = new BankAccount { AccountNumber = "004", AccountHolderName = "Invalid Name", Balance = -1000, AccountType = (AccountType)99 }; myBank.AddAccount(account4); // Input validation for depositing into an account foundAccount = myBank.SearchAccount("002"); foundAccount.Deposit(-500); // Input validation for withdrawing from an account foundAccount = myBank.SearchAccount("003"); foundAccount.Withdraw(10000); // Input validation for searching an account foundAccount = myBank.SearchAccount("1000"); Console.ReadLine(); } }
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
Related questions
Question
in C# errors are in pics
class Program
{
static void Main(string[] args)
{
Bank myBank = new Bank();
// Adding bank accounts
BankAccount account1 = new BankAccount { AccountNumber = "001", AccountHolderName = "John Doe", Balance = 5000, AccountType = AccountType.Savings };
myBank.AddAccount(account1);
BankAccount account2 = new BankAccount { AccountNumber = "002", AccountHolderName = "Jane Smith", Balance = 10000, AccountType = AccountType.Current };
myBank.AddAccount(account2);
BankAccount account3 = new BankAccount { AccountNumber = "003", AccountHolderName = "Bob Johnson", Balance = 7500, AccountType = AccountType.Savings };
myBank.AddAccount(account3);
// Searching for an existing account and displaying its details
Console.WriteLine("Enter the account number to search: ");
string accountNumber = Console.ReadLine();
BankAccount foundAccount = myBank.SearchAccount(accountNumber);
if (foundAccount != null)
{
Console.WriteLine($"Account Number: {foundAccount.AccountNumber}");
Console.WriteLine($"Account Holder Name: {foundAccount.AccountHolderName}");
Console.WriteLine($"Account Type: {foundAccount.AccountType}");
Console.WriteLine($"Balance: {foundAccount.CheckBalance()}");
}
else
{
Console.WriteLine("Account not found.");
}
// Depositing an amount into an account
Console.WriteLine("Enter the account number to deposit into: ");
accountNumber = Console.ReadLine();
foundAccount = myBank.SearchAccount(accountNumber);
if (foundAccount != null)
{
Console.WriteLine("Enter the amount to deposit: ");
double amount;
while (!double.TryParse(Console.ReadLine(), out amount))
{
Console.WriteLine("Invalid input. Please enter a number.");
}
foundAccount.Deposit(amount);
Console.WriteLine($"Deposit successful. New balance: {foundAccount.CheckBalance()}");
}
else
{
Console.WriteLine("Account not found.");
}
// Withdrawing an amount from an account
Console.WriteLine("Enter the account number to withdraw from: ");
accountNumber = Console.ReadLine();
foundAccount = myBank.SearchAccount(accountNumber);
if (foundAccount != null)
{
Console.WriteLine("Enter the amount to withdraw: ");
double amount;
while (!double.TryParse(Console.ReadLine(), out amount))
{
Console.WriteLine("Invalid input. Please enter a number.");
}
if (foundAccount.Withdraw(amount))
{
Console.WriteLine($"Withdrawal successful. New balance: {foundAccount.CheckBalance()}");
}
else
{
Console.WriteLine("Insufficient balance.");
}
}
else
{
Console.WriteLine("Account not found.");
}
// Searching for the account again and displaying the updated account details
Console.WriteLine("Enter the account number to search: ");
accountNumber = Console.ReadLine();
foundAccount = myBank.SearchAccount(accountNumber);
if (foundAccount != null)
{
Console.WriteLine($"Account Number: {foundAccount.AccountNumber}");
Console.WriteLine($"Account Holder Name: {foundAccount.AccountHolderName}");
Console.WriteLine($"Account Type: {foundAccount.AccountType}");
Console.WriteLine($"Balance: {foundAccount.CheckBalance()}");
}
else
{
Console.WriteLine("Account not found.");
}
// Removing an account
Console.WriteLine("Enter the account number to remove: ");
accountNumber = Console.ReadLine();
bool isRemoved = myBank.RemoveAccount(accountNumber);
if (isRemoved)
{
Console.WriteLine("Account removed successfully.");
}
else
{
Console.WriteLine("Account not found.");
}
// Testing additional functionality
// Input validation for adding an account
BankAccount account4 = new BankAccount { AccountNumber = "004", AccountHolderName = "Invalid Name", Balance = -1000, AccountType = (AccountType)99 };
myBank.AddAccount(account4);
// Input validation for depositing into an account
foundAccount = myBank.SearchAccount("002");
foundAccount.Deposit(-500);
// Input validation for withdrawing from an account
foundAccount = myBank.SearchAccount("003");
foundAccount.Withdraw(10000);
// Input validation for searching an account
foundAccount = myBank.SearchAccount("1000");
Console.ReadLine();
}
}
Expert Solution
Step 1
Algorithm:
- Define the BankAccount class with the following attributes: AccountNumber, AccountHolderName, Balance, and AccountType.
- Define the Bank class with the following methods: AddAccount, SearchAccount, and RemoveAccount. This class should also have a list of BankAccount objects.
- Instantiate the Bank class.
- Create BankAccount objects for each account holder with their respective account details (AccountNumber, AccountHolderName, Balance, and AccountType).
- Add the BankAccount objects to the Bank object using the AddAccount method.
- Ask the user for an account number to search for using the SearchAccount method. If found, display the account details (AccountNumber, AccountHolderName, Balance, and AccountType).
- Ask the user for an account number to deposit into using the SearchAccount method. If found, ask the user for the amount to deposit, then deposit the amount using the Deposit method and display the new balance.
- Ask the user for an account number to withdraw from using the SearchAccount method. If found, ask the user for the amount to withdraw, then withdraw the amount using the Withdraw method. If successful, display the new balance. If there is insufficient balance, display an error message.
- Ask the user for an account number to remove using the RemoveAccount method. If successful, display a message indicating the account was removed. If not successful, display an error message.
- Repeat steps 6-9 as necessary.
- Exit the program.
Step by step
Solved in 4 steps with 10 images
Knowledge Booster
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
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education