Example #1
0
 private static void PrintToppingsCalories(Queue <string> commands)
 {
     while (commands.Count > 0)
     {
         string   command        = commands.Dequeue();
         string[] toppingArgs    = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
         string   toppingsType   = toppingArgs[1];
         double   toppingsWeight = double.Parse(toppingArgs[2]);
         Topping  topping        = new Topping(toppingsType, toppingsWeight);
         Console.WriteLine($"{topping.CalculateCalories():f2}");
     }
 }
Example #2
0
        public static void Main()
        {
            var input = Console.ReadLine();

            try
            {
                while (input != "END")
                {
                    var tokens = input.Split();

                    switch (tokens[0].ToLower())
                    {
                    case "dough":
                        var flourType       = tokens[1];
                        var bakingTechnique = tokens[2];
                        var doughWeight     = double.Parse(tokens[3]);
                        var dough           = new Dough(flourType, bakingTechnique, doughWeight);
                        Console.WriteLine($"{dough.CalculateCalories():f2}");
                        break;

                    case "topping":
                        var toppingType   = tokens[1];
                        var toppingWeight = double.Parse(tokens[2]);
                        var topping       = new Topping(toppingType, toppingWeight);
                        Console.WriteLine($"{topping.CalculateCalories():f2}");
                        break;

                    case "pizza":
                        MakePizza(tokens);
                        break;
                    }
                    input = Console.ReadLine();
                }
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }