コード例 #1
0
 public void CreateSweets(Sweet sweet)
 {
     if (SugarStock > sweet.Sugar)
     {
         SweetInventory.Add(sweet);
         SugarStock -= sweet.Sugar;
     }
     else
     {
         Console.WriteLine($"Not enough sugar to create {sweet.GetType().Name}");
     }
 }
コード例 #2
0
        /// <summary>
        /// You should definitely ask for more than fifty cents.
        /// </summary>
        /// <param name="sweet"></param>
        /// <param name="quantity"></param>
        internal void Sell(Sweet sweet, int quantity)
        {
            // We can sell candie or lollipop with a given number as amount
            // If we sell sweets the income will be increased by the price of the sweets and we delete it from the inventory

            if (inventoryOfSweets.ContainsKey(sweet.GetType()))
            {
                if (inventoryOfSweets[sweet.GetType()] >= quantity)
                {
                    inventoryOfSweets[sweet.GetType()] -= quantity;
                    money += prices[sweet.GetType()] * quantity;

                    Console.WriteLine($"{quantity} pcs of {sweet.GetType().Name} sold for {prices[sweet.GetType()] * quantity}");
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Sweeet dreams are made of these ...
        /// </summary>
        /// <param name="sweet"></param>
        internal void CreateSweets(Sweet sweet)
        {
            // If we create a candie or lollipop the CandyShop's sugar amount gets reduced by the amount needed to create the sweets

            if (sugarInventory > sweet.SugarRequired)
            {
                if (!inventoryOfSweets.ContainsKey(sweet.GetType()))
                {
                    inventoryOfSweets[sweet.GetType()] = 0;
                }
                inventoryOfSweets[sweet.GetType()]++;
                sugarInventory -= sweet.SugarRequired;
                Console.WriteLine($"One pcs of {sweet.GetType().Name} created");
            }
            else
            {
                Console.WriteLine($"No {sweet.GetType().Name} created");
            }
        }
コード例 #4
0
        public void Sell(Sweet sweet, int pieces)
        {
            int inventorySum    = SweetInventory.Count;
            int candyCounter    = 0;
            int lollipopCounter = 0;

            foreach (Sweet sweetie in SweetInventory)
            {
                if (sweetie == CANDY)
                {
                    candyCounter++;
                }

                else
                {
                    lollipopCounter++;
                }
            }

            if (sweet == CANDY)
            {
                if (candyCounter > pieces)
                {
                    SweetInventory.Remove(sweet);
                    Money += sweet.Price;
                }
            }
            else
            {
                if (lollipopCounter > pieces)
                {
                    SweetInventory.Remove(sweet);
                    Money += sweet.Price;
                }
            }
        }