// See https://aka.ms/new-console-template for more information using System.Security.AccessControl; namespace BankApp { public class BankAppProg { private static List accounts = new List(); public static void Main(string[] args) { bool isAppRunning = true; while (isAppRunning) { DisplayMenu(); int choice = GetChoice(); switch (choice) { case 1: AddAccount(); break; case 2: ViewAccounts(); break; case 3: Deposit(); break; case 4: Withdraw(); break; case 5: Console.WriteLine("Exiting App"); isAppRunning = false; break; default: Console.WriteLine("Invalid Choice"); break; } } } static void DisplayMenu() { Console.Clear(); Console.WriteLine("MENU"); Console.WriteLine("-------"); Console.WriteLine("1. Add Account "); Console.WriteLine("2. View All Accounts"); Console.WriteLine("3. Deposit "); Console.WriteLine("4. Withdraw "); Console.WriteLine("5. Exit "); } static int GetChoice() { Console.WriteLine("Choose an option: "); int choice; while (!int.TryParse(Console.ReadLine(), out choice) || choice < 1 || choice > 5) { Console.WriteLine("Please enter a valid choice."); } return choice; } static void AddAccount() { Console.Clear(); Console.WriteLine("Enter Account Holder Name: "); string name = Console.ReadLine(); int accountNumber = accounts.Count + 1; Account newAccount = new Account(accountNumber, name); accounts.Add(newAccount); Console.WriteLine($"A new account has been created for {name} with the account number {accountNumber}"); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } static void ViewAccounts() { Console.Clear(); if (accounts.Count == 0) { Console.WriteLine("No accounts have been added"); } else { Console.WriteLine("ACCOUNTS"); Console.WriteLine("------------"); foreach (var account in accounts) { Console.WriteLine($"Account Number: {account.AccountNumber}"); Console.WriteLine($"Account Holder: {account.AccountHolder}"); Console.WriteLine($"Balance: ${account.Balance}"); Console.WriteLine("-------------"); } } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } static void Deposit() { // Find acc for number given Console.Clear(); Console.Write("Enter Account Number: "); int accountNumber = int.Parse(Console.ReadLine()); //lambda expressions(?) // Look up acc list array for matching number Account account = accounts.Find(a => a.AccountNumber == accountNumber); if (account != null) { Console.Write("Enter Deposit Amount: $"); double depositAmount = double.Parse(Console.ReadLine()); if (depositAmount > 0) { account.Balance += depositAmount; Console.WriteLine($"Deposited ${depositAmount} into Account {account.AccountNumber}"); Console.WriteLine($"Current Balance: ${account.Balance}"); } else { { Console.WriteLine("Deposit amount must be greater than zero"); } } } else { Console.WriteLine("Account Not Found"); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } static void Withdraw() { Console.Clear(); Console.Write("Enter Account Number: "); int accountNumber = int.Parse(Console.ReadLine()); Account account = accounts.Find(a => a.AccountNumber == accountNumber); if (account != null) { Console.Write("Enter Withdraw Amount: "); double withdrawAmount = double.Parse(Console.ReadLine()); if (withdrawAmount < 0 || withdrawAmount > account.Balance) { Console.WriteLine("Withdrawl has Failed"); } else { account.Balance -= withdrawAmount; Console.WriteLine($"Withdrawn ${withdrawAmount} from Account {account.AccountNumber}"); Console.WriteLine($"Current Balance: ${account.Balance}"); } } else { Console.WriteLine("Account Not Found"); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } } }