public override void Execute(int accountNumber, Screen atmScreen) { bool isCashDispensed = false; decimal availableBalance; BankDatabase bankDatabase = BankDatabase; do { _amount = DisplayMenuOfAmounts(atmScreen); if (_amount != CANCELED) { availableBalance = bankDatabase.GetAvailableBalance(accountNumber); if (_amount <= availableBalance) { if (_cashDispenser.IsSufficiantCashAvailable(_amount)) { bankDatabase.Debit(accountNumber, _amount); _cashDispenser.DispenseCash(_amount); isCashDispensed = true; atmScreen.DisplayMessageLine("\nYour cash has been dispensed. Please take your cash now."); } else { atmScreen.DisplayMessageLine("\nInsufficient cash available in the ATM.\n\nPlease choose a smaller amount."); } } else { atmScreen.DisplayMessage("\nInsufficient funds in your account.\n\nPlease choose a smaller amount."); } Sleep(3000); } else { atmScreen.DisplayMessageLine("\nCancelling transaction..."); Sleep(3000); return; } } while (!isCashDispensed); }
public override void Execute() { bool cashDispensed = false; decimal availableBalance; BankDatabase bankDatabase = database; Screen screen = new Screen(); do { amount = (decimal)displayMenu(); if (amount != CANCELED) { availableBalance = bankDatabase.getAvailableBalance(AccountNumber); if (amount <= availableBalance) { bankDatabase.Debit(AccountNumber, amount); cashDispenser.DispenseCash(amount); cashDispensed = true; screen.DisplayMessageLine("\nYour cash has been dispensed. Please take your cash now."); } else { screen.DisplayMessageLine("\nInsufficient funds in your account. \nPlease choose a smaller amount."); } } else { screen.DisplayMessageLine("\nCanceling transaction..."); return; } } while (!cashDispensed); }