//perform transaction public override void Execute() { processingWithdrawal = true; //get the balances decimal availableBalance = bankDatabase.GetAvailableBalance(accountNumber); decimal totalBalance = bankDatabase.GetTotalBalance(accountNumber); //array of amounts to correspond to menu numbers int[] amounts = { 0, 20, 40, 60, 100, 200 }; screen.DisplayMessage("\r\nWithdrawal options:"); screen.appendMessage("1 - $20"); screen.appendMessage("2 - $40"); screen.appendMessage("3 - $60"); screen.appendMessage("4 - $100"); screen.appendMessage("5 - $200"); screen.appendMessage("6 - Cancel transaction"); screen.appendMessage("\r\nChoose a withdrawal option (1-6): "); int selection = keypad.getSelection(); //Make sure the user input an option - Can't withdraw nothing if (selection != 0) { //pull the correct amount from the array int withdrawalAmount = amounts[selection]; if (withdrawalAmount > availableBalance) { //not enough money screen.DisplayMessage("Insufficient funds.\r\nNow Exiting..."); processingWithdrawal = false; } else { //subtract the amount if (cashDispenser.IsSufficientCashAvailable(withdrawalAmount)) { //debit the account to reflect the withdrawal bankDatabase.Debit(accountNumber, withdrawalAmount); cashDispenser.DispenseCash(withdrawalAmount); screen.DisplayMessage("\r\nPlease take your cash from the cash dispenser."); //cashDispenserLabel.ForeColor = Color.BlueViolet; processingWithdrawal = false; } else { screen.DisplayMessage("\r\nInsufficient cash available in the ATM \n\nPlease choose a smaller amount."); } } } }
private void PerformTransactions() { int mainMenuSelection; //show main menu and get user selection DisplayMainMenu(); mainMenuSelection = keypad.getSelection(); //decide how to proceed based on user's menu selection if (mainMenuSelection != 0) { Transaction transaction; switch ((MenuOption)mainMenuSelection) { //user chooses to perform one of three transaction types case MenuOption.BALANCE_INQUIRY: transaction = new BalanceInquiry(accountNumber, screen, bankDatabase); transaction.Execute(); break; case MenuOption.WITHDRAWAL: Withdrawal(); break; case MenuOption.DEPOSIT: MakeDeposit(); break; case MenuOption.EXIT_ATM: ExitATM(); break; default: screen.DisplayMessage("You did not enter a valid selection. Try again."); break; } } }