Example #1
0
File: ATM.cs Project: cdrann/ATM
        public ATM()
        {
            //creating handlers, setting initial state of ATM
            bills50s   = new CurrencyBill(50, 1);
            bills100s  = new CurrencyBill(100, 2);
            bills200s  = new CurrencyBill(200, 3);
            bills500s  = new CurrencyBill(500, 2);
            bills1000s = new CurrencyBill(1000, 4);
            bills2000s = new CurrencyBill(2000, 1);
            bills5000s = new CurrencyBill(5000, 1);

            bills50s
            .RegisterNext(bills100s)
            .RegisterNext(bills200s)
            .RegisterNext(bills500s)
            .RegisterNext(bills1000s)
            .RegisterNext(bills2000s)
            .RegisterNext(bills5000s);

            mode = "authorization";

            maxNotesAmount = 15;

            currNotesAmount = 0;
        }
Example #2
0
File: ATM.cs Project: cdrann/ATM
        public void doWithdraw(int amount, CurrencyBill firstHandler, ref int sum_dispense)
        {
            while (true)
            {
                //sender pass the request to first handler in the pipeline

                var isDepensible = firstHandler.DispenseRequest(amount, this, ref sum_dispense);
                if (!isDepensible)
                {
                    MessageBox.Show($"Failed to dispense ${amount}!");
                }
            }
        }
Example #3
0
File: ATM.cs Project: cdrann/ATM
        public int ExecuteWithdraw(bool isSmallMode, bool isLargeMode, int amount)
        {
            var currCashState            = getCurrCashInATM();
            Dictionary <int, int> source = new Dictionary <int, int>(currCashState);

            CurrencyBill firstHandler = null;

            if (isSmallMode)
            {
                //set proper handlers pipeline
                bills50s
                .RegisterNext(bills100s)
                .RegisterNext(bills200s)
                .RegisterNext(bills500s)
                .RegisterNext(bills1000s)
                .RegisterNext(bills2000s)
                .RegisterNext(bills5000s);

                firstHandler = bills50s;
            }
            else if (isLargeMode)
            {
                //set proper handlers pipeline
                bills5000s
                .RegisterNext(bills2000s)
                .RegisterNext(bills1000s)
                .RegisterNext(bills500s)
                .RegisterNext(bills200s)
                .RegisterNext(bills100s)
                .RegisterNext(bills50s);

                firstHandler = bills5000s;
            }

            int sum_dispense = 0;

            doWithdraw(amount, firstHandler, ref sum_dispense);

            return(sum_dispense);
        }
Example #4
0
 //Method that set next handler in the pipeline
 public CurrencyBill RegisterNext(CurrencyBill currencyBill)
 {
     next = currencyBill;
     return(next);
 }
Example #5
0
 //A static constructor that initializes static Zero property
 //This property is used as default next handler instead of a null object
 static CurrencyBill()
 {
     Zero = new ZeroCurrencyBill();
 }