Exemplo n.º 1
0
        public void ReturnMoney()
        {
            Money moneyToReturn = MoneyInside.AllocateToReturn(AmountInTransaction);

            MoneyInside -= moneyToReturn;

            this.AmountInTransaction = 0;
        }
Exemplo n.º 2
0
        public void TakeMoney(decimal amount)
        {
            if (CanTakeMoney(amount))
            {
                var moneyToReturn = MoneyInside.AllocateToReturn(amount);

                MoneyInside -= moneyToReturn;

                MoneyCharged += CalculateCommission(amount);
            }
        }
Exemplo n.º 3
0
        public void BuySnack(int position)
        {
            // Don't allow purchase if not enough money inserted
            if (GetSlot(position).SnackPile.Price > this.AmountInTransaction)
            {
                throw new InvalidOperationException();
            }

            Slot slot = GetSlot(position);

            slot.SnackPile = slot.SnackPile.SubtractOne();

            //find the amount of change to return
            Money change = MoneyInside.AllocateToReturn(AmountInTransaction - slot.SnackPile.Price);

            if (change.Amount < AmountInTransaction - slot.SnackPile.Price)
            {
                throw new CannotMakeChangeException();
            }

            MoneyInside        -= change;
            AmountInTransaction = 0;
        }