예제 #1
0
 /// <summary>
 /// no-argument ATM constructor initializes instance variables
 /// </summary>
 public ATM()
 {
     _userAuthenticated    = false;
     _currentAccountNumber = 0;
     _depositSlot          = new DepositSlot();
     _keypad        = new Keypad();
     _screen        = new Screen();
     _cashDispenser = new CashDispenser();
     _bankDatabase  = new BankDatabase();
 }
        public override void Execute()
        {
            bool    isCashDispensed = false;
            decimal availableBalance;

            BankDatabase bankDatabase = base.BankDatabase;

            do
            {
                _amount = (decimal)DisplayMenuOfAmounts();

                if (_amount != CANCELED)
                {
                    availableBalance = bankDatabase.getAvailableBalance(AccountNumber);
                    if (_amount <= availableBalance)
                    {
                        if (CashDispenser.IsSufficiantCashAvailable(_amount))
                        {
                            bankDatabase.Debit(AccountNumber, _amount);
                            CashDispenser.DispenseCash(_amount);
                            isCashDispensed = true;

                            Screen.DisplayMessageLine("\nYour cash has been dispensed. Please take your cash now.");
                        }
                        else
                        {
                            Screen.DisplayMessageLine("\nInsufficient cash available in the ATM.\n\nPlease choose a smaller amount.");
                        }
                    }
                    else
                    {
                        Screen.DisplayMessage("\nInsufficient funds in your account.\n\nPlease choose a smaller amount.");
                    }
                    Sleep(3000);
                }
                else
                {
                    Screen.DisplayMessageLine("\nCancelling transaction...");
                    Sleep(3000);
                    return;
                }
            } while (!isCashDispensed);
        }
        const int CANCELED = 7; // Kullanıcının çekmek istediği para miktarını kendisinin belirlemesi için bir seçenek daha eklendi.(Ek özellik)

        public Withdrawal(int userAccount, Screen screen,
                          BankDatabase bankDatabase, Keypad keypad, CashDispenser cashDispenser) : base(userAccount, bankDatabase, screen)
        {
            this.keypad        = keypad;
            this.cashDispenser = cashDispenser;
        }