예제 #1
0
        /// <summary>
        /// Remove coin from the wallet
        /// </summary>
        /// <param name="coin">coin to remove</param>
        /// <returns>removed coin</returns>
        /// <exceprion cref="InvalidOperationException">is thrown if provided coins is absent</exceprion>
        public virtual Coin Pop(Coin coin)
        {
            if (!_coins.ContainsKey(coin))
            {
                throw new InvalidOperationException("There are not specified coins");
            }

            return _coins[coin].Pop();
        }
예제 #2
0
        /// <summary>
        /// Adds coin to the wallet
        /// </summary>
        /// <param name="coin">coin to add</param>
        public virtual void Push(Coin coin)
        {
            if (!_coins.ContainsKey(coin))
            {
                _coins.Add(coin, new Stack<Coin>());
            }

            _coins[coin].Push(coin);
        }
예제 #3
0
        /// <summary>
        /// Calculates amount of specified coins
        /// </summary>
        /// <param name="coin">coin is required to check</param>
        /// <returns>specified coins amount</returns>
        public int GetAmount(Coin coin)
        {
            if (!_coins.ContainsKey(coin))
            {
                return 0;
            }

            return _coins[coin].Count;
        }
예제 #4
0
        public static void PayDay(this Customer c)
        {
            Coin c1 = new Coin(1);
            Coin c2 = new Coin(2);
            Coin c3 = new Coin(5);
            Coin c4 = new Coin(10);

            c.Get(c1, 9);
            ////c.Get(c2, 7);
            ////c.Get(c3, 5);
            ////c.Get(c4, 10);
        }
예제 #5
0
 public bool isAvaliable(Coin c)
 {
     return (wallet.Contains(c) && wallet[c] > 0);
 }
예제 #6
0
 public void Get(Coin coin, int Amount = 1)
 {
     wallet.Add(coin, Amount);
 }
 public void Insert(Customer c, Coin coin)
 {
     if (isAvaliable(coin))
     {
         coinStorage.Add(coin);
         totalBill += coin.Rating;
     }
     else
         c.Get(coin);
 }
 public void Insert(Coin coin)
 {
     if (isAvaliable(coin))
         coinStorage.Add(coin);
 }
        private bool isAvaliable(Coin coin)
        {
            bool result = false;
            foreach (Coin c in avaliableCoins)
            {
                if (c.Rating == coin.Rating)
                    result = true;
            }
            if (!result)
                display.Show("Автомат " + Name + " не принимает таких монет.");

            return result;
        }
 public virtual void Insert(Coin coin)
 {
     changer.Process(coin);
     if (ExactChange)
         DeliverGood(Selection);
 }
예제 #11
0
파일: VMControl.cs 프로젝트: alex606/cis501
 /// <summary>
 /// Method to Connect Cans and Coins objects with Controller
 /// </summary>
 /// <param name="Coins"></param>
 /// <param name="Cans"></param>
 /// <param name="InitCans"></param>
 /// <param name="InitCoins"></param>
 /// <param name="?"></param>
 public void initMachine(Coin[] Coins, Can[] Cans, int[] InitCans, int[] InitCoins)
 {
     _Coins = Coins;
     _Cans = Cans;
     _initCans = InitCans;
     _initCoins = InitCoins;
 }
예제 #12
0
 public void Spend(Coin c, int amount = 1)
 {
     wallet.Remove(c);
     Console.WriteLine("Монетка со звоном падает в монетоприемник.");
     Console.WriteLine();
 }
 public NoCoinWithSuchNominalInWalletException(Coin coin) :
     base(
         String.Format("Wallet doesn't contain coins with nominal {0}.", coin.Nominal)
     )
 {}
예제 #14
0
 public CoinInserter(Coin coin)
 {
     _coin = coin;
     //_total = Total;
 }
예제 #15
0
        private void Pay_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
            var denomination = (decimal)button.DataContext;

            var coin = new Coin(denomination, _currentRegion);
            if (CustomerWallet.GetAmount(coin) > 0)
            {
                CustomerWallet.Pop(coin);
                ReceivedMoney.Push(coin);
                RefreshData();
            }
        }
예제 #16
0
        public static double GetCoinValue(int size, int weight)
        {
            Coin currentCoin = Constant.CoinItems.Where(c => c.Size == size && c.Weight == weight).FirstOrDefault();

            return(currentCoin == null ? 0 : currentCoin.Value);
        }
예제 #17
0
        private void Form1_Load(object sender, EventArgs e)
        {
            amountDisplay = new AmountDisplay(txtAmount);

            displayNum10Yen = new DebugDisplay(txtNum10Yen);
            displayNum50Yen = new DebugDisplay(txtNum50Yen);
            displayNum100Yen = new DebugDisplay(txtNum100Yen);
            displayNum500Yen = new DebugDisplay(txtNum500Yen);
            displayPrice0 = new DebugDisplay(txtPrice0);
            displayPrice1 = new DebugDisplay(txtPrice1);
            displayPrice2 = new DebugDisplay(txtPrice2);
            displayPrice3 = new DebugDisplay(txtPrice3);
            displayName0 = new DebugDisplay(txtName0);
            displayName1 = new DebugDisplay(txtName1);
            displayName2 = new DebugDisplay(txtName2);
            displayName3 = new DebugDisplay(txtName3);
            displayNumCans0 = new DebugDisplay(txtNumCan0);
            displayNumCans1 = new DebugDisplay(txtNumCan1);
            displayNumCans2 = new DebugDisplay(txtNumCan2);
            displayNumCans3 = new DebugDisplay(txtNumCan3);

            soldOutLight0 = new Light(pbxSOLight0, Color.Orange);
            soldOutLight1 = new Light(pbxSOLight1, Color.Orange);
            soldOutLight2 = new Light(pbxSOLight2, Color.Orange);
            soldOutLight3 = new Light(pbxSOLight3, Color.Orange);

            noChangeLight = new TimerLight(pbxNoChange, Color.Red, timer1);

            purchasableLight0 = new Light(pbxPurLight0, Color.Aqua);
            purchasableLight1 = new Light(pbxPurLight1, Color.Aqua);
            purchasableLight2 = new Light(pbxPurLight2, Color.Aqua);
            purchasableLight3 = new Light(pbxPurLight3, Color.Aqua);

            coinDispenser10Yen = new CoinDispenser(txtChange10Yen);
            coinDispenser50Yen = new CoinDispenser(txtChange50Yen);
            coinDispenser100Yen = new CoinDispenser(txtChange100Yen);
            coinDispenser500Yen = new CoinDispenser(txtChange500Yen);

            // All candispensers share the same output textbox for simulation
            canDispenser0 = new CanDispenser(txtCanDispenser, CANNAMES[0]);
            canDispenser1 = new CanDispenser(txtCanDispenser, CANNAMES[1]);
            canDispenser2 = new CanDispenser(txtCanDispenser, CANNAMES[2]);
            canDispenser3 = new CanDispenser(txtCanDispenser, CANNAMES[3]);

            // Instantiate your entity and control objects
            // Connect these objects
            Light[] purchaseLights = { purchasableLight0, purchasableLight1, purchasableLight2, purchasableLight3 };
            Light[] soldOutLights = { soldOutLight0, soldOutLight1, soldOutLight2, soldOutLight3 };

            Total = new VMControl(amountDisplay, purchaseLights, noChangeLight, soldOutLights);

            tenYenCoin = new Coin(COINVALUES[0], NUMCOINS[0], coinDispenser10Yen,Total);
            fiftyYenCoin = new Coin(COINVALUES[1], NUMCOINS[1], coinDispenser50Yen,Total);
            hundredYenCoin = new Coin(COINVALUES[2], NUMCOINS[2],coinDispenser100Yen,Total);
            fiveHundredYenCoin = new Coin(COINVALUES[3], NUMCOINS[3], coinDispenser500Yen,Total);

            // You must replace the following default constructors with
            // constructors with arguments (non-default constructors)
            // to pass (set) the first object that ButtonPressed() will
            // visit

            coke = new Can(CANPRICES[0], NUMCANS[0], CANNAMES[0], canDispenser0, Total, purchasableLight0, soldOutLight0);
            pepsi = new Can(CANPRICES[1], NUMCANS[1], CANNAMES[1], canDispenser1, Total, purchasableLight1, soldOutLight1);
            pepper = new Can(CANPRICES[2], NUMCANS[2], CANNAMES[2], canDispenser2, Total, purchasableLight2, soldOutLight2);
            sprite = new Can(CANPRICES[3], NUMCANS[3], CANNAMES[3], canDispenser3, Total, purchasableLight3, soldOutLight3);

            purchaseButton0 = new PurchaseButton(coke);
            purchaseButton1 = new PurchaseButton(pepsi);
            purchaseButton2 = new PurchaseButton(pepper);
            purchaseButton3 = new PurchaseButton(sprite);

            Can[] Cans = { coke, pepsi, pepper, sprite };
            Coin[] Coins = { tenYenCoin, fiftyYenCoin, hundredYenCoin, fiveHundredYenCoin };

            CanDispenser[] canDispensors = { canDispenser0, canDispenser1, canDispenser2, canDispenser3 };
            CoinDispenser[] coinDispensors = { coinDispenser10Yen, coinDispenser50Yen, coinDispenser100Yen, coinDispenser500Yen };

            Total.initMachine(Coins, Cans, NUMCANS, NUMCOINS);

            // You must replace the following default constructors with
            // constructors that take armuments to pass the first object that
            // the CoinInserted() will call
            coinInserter10Yen = new CoinInserter(tenYenCoin);
            coinInserter50Yen = new CoinInserter(fiftyYenCoin);
            coinInserter100Yen = new CoinInserter(hundredYenCoin);
            coinInserter500Yen = new CoinInserter(fiveHundredYenCoin);

            coinReturnButton = new CoinReturnButton(Total);

            // Display debug information
            displayCanPricesAndNames();
            updateDebugDisplays();
        }
예제 #18
0
파일: VMControl.cs 프로젝트: alex606/cis501
 /// <summary>
 /// Method to update coin inventory after inserting a coin
 /// </summary>
 /// <param name="coin"></param>
 public void UpdateCredit(Coin coin)
 {
     credit += coin.coinValue;
     UpdateDisplay();
 }
        /// <summary>
        /// Adds coin to the wallet
        /// </summary>
        /// <param name="coin">coin to add</param>
        /// <exception cref="ArgumentException">is thrown if unsupported coin currency is provided</exception>
        public override void Push(Coin coin)
        {
            if (coin.Currency != _currency)
            {
                throw new ArgumentException("Provided coins currency isn't supported", "coin");
            }

            base.Push(coin);
        }
 public CoinsLessThanNecessaryException(Coin contain, uint containCount, Coin nec, uint necCount) :
     base(String.Format(
         "Wallet contains {0} coins with nominal {1}. And you need {2} coins with nominal {3}.", 
         containCount, contain.Nominal, necCount, nec.Nominal
     )) 
 {}
예제 #21
0
        private void Form1_Load(object sender, EventArgs e)
        {
            amountDisplay = new AmountDisplay(txtAmount);

            displayNum10Yen  = new DebugDisplay(txtNum10Yen);
            displayNum50Yen  = new DebugDisplay(txtNum50Yen);
            displayNum100Yen = new DebugDisplay(txtNum100Yen);
            displayNum500Yen = new DebugDisplay(txtNum500Yen);
            displayPrice0    = new DebugDisplay(txtPrice0);
            displayPrice1    = new DebugDisplay(txtPrice1);
            displayPrice2    = new DebugDisplay(txtPrice2);
            displayPrice3    = new DebugDisplay(txtPrice3);
            displayName0     = new DebugDisplay(txtName0);
            displayName1     = new DebugDisplay(txtName1);
            displayName2     = new DebugDisplay(txtName2);
            displayName3     = new DebugDisplay(txtName3);
            displayNumCans0  = new DebugDisplay(txtNumCan0);
            displayNumCans1  = new DebugDisplay(txtNumCan1);
            displayNumCans2  = new DebugDisplay(txtNumCan2);
            displayNumCans3  = new DebugDisplay(txtNumCan3);

            soldOutLight0 = new Light(pbxSOLight0, Color.Orange);
            soldOutLight1 = new Light(pbxSOLight1, Color.Orange);
            soldOutLight2 = new Light(pbxSOLight2, Color.Orange);
            soldOutLight3 = new Light(pbxSOLight3, Color.Orange);

            noChangeLight = new TimerLight(pbxNoChange, Color.Red, timer1);

            purchasableLight0 = new Light(pbxPurLight0, Color.Aqua);
            purchasableLight1 = new Light(pbxPurLight1, Color.Aqua);
            purchasableLight2 = new Light(pbxPurLight2, Color.Aqua);
            purchasableLight3 = new Light(pbxPurLight3, Color.Aqua);

            coinDispenser10Yen  = new CoinDispenser(txtChange10Yen);
            coinDispenser50Yen  = new CoinDispenser(txtChange50Yen);
            coinDispenser100Yen = new CoinDispenser(txtChange100Yen);
            coinDispenser500Yen = new CoinDispenser(txtChange500Yen);

            // All candispensers share the same output textbox for simulation
            canDispenser0 = new CanDispenser(txtCanDispenser, CANNAMES[0]);
            canDispenser1 = new CanDispenser(txtCanDispenser, CANNAMES[1]);
            canDispenser2 = new CanDispenser(txtCanDispenser, CANNAMES[2]);
            canDispenser3 = new CanDispenser(txtCanDispenser, CANNAMES[3]);

            //initialize cans
            for (int i = 0; i < 4; i++)
            {
                allProduct[i] = new Can(CANNAMES[i], CANPRICES[i], NUMCANS[i]);
                userMoney[i]  = new Coin(COINVALUES[i], NUMCOINS[i]);
            }

            // You must replace the following default constructors with
            // constructors with arguments (non-default constructors)
            // to pass (set) the first object that ButtonPressed() will
            // visit
            purchaseButton0 = new PurchaseButton(allProduct[0]);
            purchaseButton1 = new PurchaseButton(allProduct[1]);
            purchaseButton2 = new PurchaseButton(allProduct[2]);
            purchaseButton3 = new PurchaseButton(allProduct[3]);

            // You must replace the following default constructors with
            // constructors that take armuments to pass the first object that
            // the CoinInserted() will call
            coinInserter10Yen  = new CoinInserter(userMoney[0]);
            coinInserter50Yen  = new CoinInserter(userMoney[1]);
            coinInserter100Yen = new CoinInserter(userMoney[2]);
            coinInserter500Yen = new CoinInserter(userMoney[3]);

            coinReturnButton = new CoinReturnButton(userMoney[0]);

            //add in lights so they can be easily turned on
            allProduct[0].purchaseLight = purchasableLight0;
            allProduct[1].purchaseLight = purchasableLight1;
            allProduct[2].purchaseLight = purchasableLight2;
            allProduct[3].purchaseLight = purchasableLight3;

            allProduct[0].soldOutLight = soldOutLight0;
            allProduct[1].soldOutLight = soldOutLight1;
            allProduct[2].soldOutLight = soldOutLight2;
            allProduct[3].soldOutLight = soldOutLight3;

            allProduct[0].productCanDispenser = canDispenser0;
            allProduct[1].productCanDispenser = canDispenser1;
            allProduct[2].productCanDispenser = canDispenser2;
            allProduct[3].productCanDispenser = canDispenser3;

            CoinDispenser[] tempAllCoinDispensers = { coinDispenser10Yen, coinDispenser50Yen, coinDispenser100Yen, coinDispenser500Yen };
            Coin.AllCoinDispensers = tempAllCoinDispensers;

            // Display debug information
            displayCanPricesAndNames();
            updateDebugDisplays();
        }