Esempio n. 1
0
 public void StartState()
 {
     DisplayMessage.Push(
         CoinInventory.TotalValue() < new decimal(0.50)
             ? Tags.ExactChange
             : Tags.InsertCoin);
     DisplayAmount.Push($"{TotalDeposit:C}");
 }
 public void ResetMachine()
 {
     CoinInventory.ClearInventory();
     m_ProductInventory.ClearInventory();
     m_TotalMachineRevenue = 0;
     m_CurrentProduct      = null;
     m_CurrentBalance      = 0;
 }
Esempio n. 3
0
        internal DefaultContext()
        {
            AcceptedDenomitationList.Add(CoinType.Quarter);
            AcceptedDenomitationList.Add(CoinType.Nickel);
            AcceptedDenomitationList.Add(CoinType.Dime);

            AvailableBins.Deposit(CreateDefaultBins());
            CoinInventory.Deposit(CreateDefaultCoinInventory());
            TotalDeposit = 0;
            TraceList.Clear();
        }
Esempio n. 4
0
        public void MakeChange(decimal productCost)
        {
            var coins = new List <ICoin>();

            var cost                 = productCost;
            var deposited            = DepositedCoins.TotalValue();
            var amountOwedToCustomer = deposited - cost;
            var refundRemaining      = amountOwedToCustomer;

            if ((amountOwedToCustomer % new decimal(0.25)) < amountOwedToCustomer)
            {
                var numOfCoins = (int)(amountOwedToCustomer / new decimal(0.25));
                for (var i = 0; i < numOfCoins; i++)
                {
                    coins.Add(Coin.Quarter);
                }

                refundRemaining      = refundRemaining % new decimal(0.25);
                amountOwedToCustomer = refundRemaining;
            }

            if ((amountOwedToCustomer % new decimal(0.10)) < amountOwedToCustomer)
            {
                var numOfCoins = (int)(amountOwedToCustomer / new decimal(0.10));
                for (var i = 0; i <= numOfCoins; i++)
                {
                    coins.Add(Coin.Dime);
                }

                refundRemaining      = refundRemaining % new decimal(0.10);
                amountOwedToCustomer = refundRemaining;
            }

            if ((amountOwedToCustomer % new decimal(0.05)) < amountOwedToCustomer)
            {
                var numOfCoins = (int)(amountOwedToCustomer / new decimal(0.05));
                for (var i = 0; i <= numOfCoins; i++)
                {
                    coins.Add(Coin.Nickel);
                }

                refundRemaining      = refundRemaining % new decimal(0.05);
                amountOwedToCustomer = refundRemaining;
            }

            foreach (var coin in coins)
            {
                CoinInventory.Remove(coin);
                CoinReturn.Deposit(coin.ToMetal());
            }
        }
        public void RefillAll(int i_counter)
        {
            for (int i = 0; i < i_counter; i++)
            {
                foreach (eCoin coin in Enum.GetValues(typeof(eCoin)))
                {
                    CoinInventory.AddItem(coin);
                }

                foreach (eProduct product in Enum.GetValues(typeof(eProduct)))
                {
                    m_ProductInventory.AddItem(product);
                }
            }
        }
        public List <eCoin> GetChange(int i_Amount)
        {
            List <eCoin> changeList = new List <eCoin>();
            int          balance    = i_Amount;

            if (i_Amount > 0)
            {
                while (balance > 0)
                {
                    if (balance >= (int)eCoin.QUARTER && CoinInventory.getQuantity(eCoin.QUARTER) > 0)
                    {
                        changeAndCoinInventoryHandler(eCoin.QUARTER, ref changeList, ref balance);
                        continue;
                    }
                    else if (balance >= (int)eCoin.DIME && CoinInventory.getQuantity(eCoin.DIME) > 0)
                    {
                        changeAndCoinInventoryHandler(eCoin.DIME, ref changeList, ref balance);
                        continue;
                    }
                    else if (balance >= (int)eCoin.NICKEL && CoinInventory.getQuantity(eCoin.NICKEL) > 0)
                    {
                        changeAndCoinInventoryHandler(eCoin.NICKEL, ref changeList, ref balance);
                        continue;
                    }
                    else if (balance >= (int)eCoin.PENNY && CoinInventory.getQuantity(eCoin.PENNY) > 0)
                    {
                        changeAndCoinInventoryHandler(eCoin.PENNY, ref changeList, ref balance);
                        continue;
                    }
                    else
                    {
                        Refund();
                        throw new NoSufficientChangeException();
                    }
                }
            }

            return(changeList);
        }
 public void InsertCoin(eCoin i_Coin)
 {
     m_CurrentBalance += (int)i_Coin;
     CoinInventory.AddItem(i_Coin);
 }
 private void changeAndCoinInventoryHandler(eCoin i_eCoin, ref List <eCoin> io_ChangeList, ref int io_balance)
 {
     io_ChangeList.Add(i_eCoin);
     io_balance -= (int)i_eCoin;
     CoinInventory.RemoveItem(i_eCoin);
 }
 internal NotEnoughCoinInventoryContext()
 {
     CoinInventory.Clear();
 }