Пример #1
0
        static void Main(string[] args)
        {
            var   command  = string.Empty;
            Pizza thePizza = null;

            try
            {
                while ((command = Console.ReadLine()) != "END")
                {
                    var commandInList = command.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                    var product       = commandInList[0];
                    if (product.ToLower() == "pizza")
                    {
                        var pizzaName = commandInList[1];
                        thePizza = new Pizza(pizzaName);
                    }
                    else if (product.ToLower() == "dough")
                    {
                        var type     = commandInList[1];
                        var tehnique = commandInList[2];
                        var grams    = int.Parse(commandInList[3]);
                        var dough    = new Dough(type, tehnique, grams);
                        thePizza.Dough = dough;
                    }
                    else if (product.ToLower() == "topping")
                    {
                        var type    = commandInList[1];
                        var grams   = int.Parse(commandInList[2]);
                        var topping = new Topping(type, grams);
                        thePizza.AddTopping(topping);
                    }
                }
                Console.WriteLine($"{thePizza.Name} - {thePizza.GetTotalCalories():F2} Calories.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var pizzaName       = Console.ReadLine().Split()[1];
            var doughData       = Console.ReadLine().Split();
            var flourType       = doughData[1];
            var bakingTechnique = doughData[2];
            int weight          = int.Parse(doughData[3]);

            try
            {
                var dough = new Dough(flourType, bakingTechnique, weight);
                var pizza = new Pizza(pizzaName, dough);
                while (true)
                {
                    var line = Console.ReadLine();
                    if (line == "END")
                    {
                        break;
                    }

                    var parts = line.Split();

                    var toppingName   = parts[1];
                    var toppingWeight = int.Parse(parts[2]);

                    var topping = new Topping(toppingName, toppingWeight);
                    pizza.AddTopping(topping);
                }

                Console.WriteLine($"{pizza.Name} - {pizza.GetCalories():F2} Calories.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }