Example #1
0
        //public virtual void LoadSnacks(int position, Snack snack, int quantity, decimal price)
        public virtual void LoadSnacks(int position, SnackPile snackPile)
        {
            Slot slot = GetSlot(position);

            //slot.Snack = snack;
            //slot.Quantity = quantity;
            //slot.Price = price;
            slot.SnackPile = snackPile;
            slot.Position  = position;
        }
Example #2
0
 public Slot(SnackMachine snackMachine, int position)
 //public Slot(SnackMachine snackMachine, int position, Snack snack, int quantity, decimal price)
     : this()
 {
     SnackMachine = snackMachine;
     Position     = position;
     //Snack = snack ;
     //Quantity = quantity;
     //Price = price;
     //SnackPile = new SnackPile(Snack.None, 0, 0m);
     SnackPile = SnackPile.EmptySnackPile;
 }
Example #3
0
        /***********************************************************************************************
         * Command-query separation principle (a part from some cases : e.g. removing a file!)
         *  - BuySnack (Commands are void) : doesn't return value : just side effects (i.e. mutates objects state)
         *  - CanBuySnack (Queries are non-void ): return a boolean value with no side effects
         ************************************************************************************************/
        public virtual string CanBuySnack(int position)
        {
            SnackPile snackPile = GetSnackPile(position);

            if (snackPile.Quantity == 0)
            {
                return("The snack pile is empty");
            }

            if (MoneyInTransaction < snackPile.Price)
            {
                return("Not enough money");
            }

            if (!MoneyInside.CanAllocate(MoneyInTransaction - snackPile.Price))
            {
                return("Not enough change!");
            }

            return(string.Empty);
        }