コード例 #1
0
ファイル: VMachine.cs プロジェクト: getson/VendingMachine
 public VMachine(
     Wallet wallet, Inventory stock,
     PricesProvider pricesProvider, IChangeCalculator changeCalculator
     )
 {
     State             = new ReadyToSellProduct(wallet, stock, pricesProvider, this);
     _changeCalculator = changeCalculator;
 }
コード例 #2
0
        public ReadyToSellProduct(
            Wallet wallet, Inventory inventory,
            PricesProvider pricesProvider, VMachine machine
            )
        {
            InsertedCoins = new List <Coin>();

            Wallet         = wallet;
            Inventory      = inventory;
            PricesProvider = pricesProvider;
            VendingMachine = machine;
        }
コード例 #3
0
        public override void InsertCoins(IEnumerable <Coin> coins)
        {
            InsertedCoins.AddRange(coins);

            var productCost = PricesProvider.GetPrice(SelectedProduct);
            var diff        = productCost - InsertedCoins.Sum(x => (int)x);

            if (diff > 0)
            {
                throw new NotSufficientAmountException("Insufficient amount!", string.Format("{0:N2} Euro", (decimal)diff / 100));
            }
            VendingMachine.State = new ReadyToProcessOrder(this);
        }