Esempio n. 1
0
    // perform transaction, overrides Transaction's abstract method
    public override void Execute()
    {
        bool cashDispensed = false; // cash was not dispensed yet

        // transaction was not canceled yet
        bool transactionCanceled = false;

        // loop until cash is dispensed or the user cancels
        do
        {
            // obtain the chosen withdrawal amount from the user
            int selection = DisplayMenuOfAmounts();

            // check whether user chose a withdrawal amount or canceled
            if (selection != CANCELED)
            {
                // set amount to the selected dollar amount
                amount = selection;

                // get available balance of account involved
                decimal availableBalance =
                    Database.GetAvailableBalance(AccountNumber);

                // check whether the user has enough money in the account
                if (amount <= availableBalance)
                {
                    // check whether the cash dispenser has enough money
                    if (cashDispenser.IsSufficientCashAvailable(amount))
                    {
                        // debit the account to reflect the withdrawal
                        Database.Debit(AccountNumber, amount);

                        cashDispenser.DispenseCash(amount); // dispense cash
                        cashDispensed = true;               // cash was dispensed

                        // instruct user to take cash
                        UserScreen.DisplayMessageLine(
                            "\nPlease take your cash from the cash dispenser.");
                    }
                    else // cash dispenser does not have enough cash
                    {
                        UserScreen.DisplayMessageLine(
                            "\nInsufficient cash available in the ATM." +
                            "\n\nPlease choose a smaller amount.");
                    }
                }
                else // not enough money available in user's account
                {
                    UserScreen.DisplayMessageLine(
                        "\nInsufficient cash available in your account." +
                        "\n\nPlease choose a smaller amount.");
                }
            }
            else
            {
                UserScreen.DisplayMessageLine("\nCanceling transaction...");
                transactionCanceled = true; // user canceled the transaction
            }
        } while ((!cashDispensed) && (!transactionCanceled));
    }
Esempio n. 2
0
        public void TestDispense()
        {
            decimal       input         = 1;
            decimal       initialCount  = 500;
            CashDispenser cashDispenser = new CashDispenser();

            cashDispenser.DispenseCash(input * 20);

            Assert.AreEqual(cashDispenser.GetBillCount(), initialCount - input);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }