Exemplo n.º 1
0
 public VendingMachine(Beverage[] menu)
 {
     Menu  = new ObservableCollection <Beverage>(menu);
     Stock = new IngredientsCollction();
     Money = default;
     //load the stock with empty ingredients
     LoadAllStockItems();
 }
Exemplo n.º 2
0
        //prepare to beverage based on the data known and by overrides in the derived class
        internal string Prepare(IngredientsCollction stock)
        {
            string res = $"Making: {Name}\n{AddIngredients(stock)}\n{Stir()}";

            //reset sugar
            Recipe.ResetAmount(IngredientsEnum.Sugar);
            return(res);
        }
Exemplo n.º 3
0
 protected Beverage(string name, string image, decimal price)
 {
     Name   = name;
     Image  = image;
     Price  = price;
     Recipe = new IngredientsCollction
     {
         { IngredientsEnum.Sugar, 0 }
     };
 }
Exemplo n.º 4
0
 //check if the collection contains the parameter collection
 internal bool CanMake(IngredientsCollction recipe, out KeyValuePair <IngredientsEnum, int> missingIngredinet)
 {
     foreach (var ingredient in recipe._inerCollection)
     {
         //check if available in stock
         if (ingredient.Value > _inerCollection[ingredient.Key])
         {
             missingIngredinet = new KeyValuePair <IngredientsEnum, int>
                                     (ingredient.Key, ingredient.Value - _inerCollection[ingredient.Key]);
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 5
0
        //adding all of the ingredients in the Recipe
        private string AddIngredients(IngredientsCollction stock)
        {
            _sb = new StringBuilder("Adding:\n");

            foreach (var ingredient in Recipe)
            {
                if (ingredient.Value != 0)
                {
                    //create the string
                    _sb.AppendLine($"{ingredient.Value} {ingredient.Key}");
                    //use ingredient
                    stock.UseIngredient(ingredient);
                }
            }
            return(_sb.ToString());
        }