Exemple #1
0
        private static void PrintPizza(string input)
        {
            var pizzaData     = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var pizzaName     = pizzaData[1];
            var toppingsCount = int.Parse(pizzaData[2]);

            if (toppingsCount < 0 || toppingsCount > 10)
            {
                throw new ArgumentException($"Number of toppings should be in range [0..10].");
            }

            var doughData   = Console.ReadLine().ToLower().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var flourType   = doughData[1];
            var technique   = doughData[2];
            var doughWeight = int.Parse(doughData[3]);

            Dough dough = new Dough(flourType, technique, doughWeight);

            Pizza pizza = new Pizza(pizzaName, dough);

            for (int i = 0; i < toppingsCount; i++)
            {
                var toppingTokens = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                var toppingType   = toppingTokens[1];
                var toppingWeight = int.Parse(toppingTokens[2]);

                var topping = new Topping(toppingType, toppingWeight);

                pizza.AddTopping(topping);
            }
            Console.WriteLine(pizza.ToString());
        }
Exemple #2
0
        public static void Main()
        {
            var input = Console.ReadLine();

            var tokens = input.Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (tokens[0] == "Pizza")
            {
                var pizzaName     = tokens[1];
                var toppingsCount = int.Parse(tokens[2]);

                try
                {
                    var pizza = new Pizza(pizzaName, toppingsCount);

                    AddDough(Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
                    pizza.DoughType = dough;

                    for (int i = 0; i < toppingsCount; i++)
                    {
                        AddTopping(Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
                    }
                    pizza.Toppings = toppings.ToArray();

                    Console.WriteLine(pizza.ToString());
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return;
                }
            }
            else
            {
                while (input != "END")
                {
                    tokens = input.Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    switch (tokens[0])
                    {
                    case "Dough":
                        try
                        {
                            AddDough(tokens);
                            Console.WriteLine($"{dough.CalculateDoughCalories():f2}");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                            return;
                        }
                        break;

                    case "Topping":
                        try
                        {
                            AddTopping(tokens);
                            Console.WriteLine($"{toppings[0].CalculateToppingCalories():f2}");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                            return;
                        }
                        break;
                    }

                    input = Console.ReadLine();
                }
            }
        }