private static void Main()
        {
            var input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            try
            {
                while (!input[0].Equals("END"))
                {
                    switch (input[0])
                    {
                    case "Pizza":
                        Pizza pizza = CreatePizza(input);
                        Console.WriteLine($"{pizza.Name} - {pizza.GetTotalCalories():F2} Calories.");
                        break;

                    case "Dough":
                        Dough dough = CreateDough(input);
                        Console.WriteLine($"{dough.GetCalories():F2}");
                        break;

                    case "Topping":
                        Topping topping = CreateTopping(input);
                        Console.WriteLine($"{topping.GetCalories():F2}");
                        break;
                    }

                    input = Console.ReadLine()
                            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                }
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #2
0
        public static void Main()
        {
            string input;

            while ((input = Console.ReadLine()) != "END")
            {
                var pizzaArgs = input.Split().Select(x => x.ToLower()).ToArray();

                try
                {
                    if (pizzaArgs[0] == "dough")
                    {
                        var doughCheck = new Dough(pizzaArgs[1], pizzaArgs[2], double.Parse(pizzaArgs[3]));
                        Console.WriteLine($"{doughCheck.GetCalories():f2}");
                    }
                    else if (pizzaArgs[0] == "topping")
                    {
                        var topping = new Topping(pizzaArgs[1], double.Parse(pizzaArgs[2]));
                        Console.WriteLine($"{topping.GetCalories():f2}");
                    }
                    else if (pizzaArgs[0] == "pizza")
                    {
                        var numberOfToppings = int.Parse(pizzaArgs[2]);

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

                        var pizzaName = pizzaArgs[1];

                        var doughArgs   = Console.ReadLine().Split().Select(x => x.ToLower()).ToArray();
                        var doughType   = doughArgs[1];
                        var doughTech   = doughArgs[2];
                        var doughWeight = double.Parse(doughArgs[3]);

                        var dough = new Dough(doughType, doughTech, doughWeight);

                        var pizza = new Pizza(pizzaName, dough);

                        for (int i = 0; i < numberOfToppings; i++)
                        {
                            var toppingArgs   = Console.ReadLine().Split().Select(x => x.ToLower()).ToArray();
                            var toppingType   = toppingArgs[1];
                            var toppingWeight = double.Parse(toppingArgs[2]);

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

                        Console.WriteLine($"{pizza.Name} - {pizza.GetTotalCalories():F2} Calories.");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return;
                }
            }
        }
Beispiel #3
0
        public static void Main()
        {
            try
            {
                string input;

                while ((input = Console.ReadLine()) != "END")
                {
                    string[] elements = input.Split(' ');
                    string   kind     = elements[0];

                    if (kind.ToLower() == "pizza")
                    {
                        string pizzaName        = elements[1];
                        int    numberOfToppings = int.Parse(elements[2]);

                        Pizza pizza = new Pizza(pizzaName, numberOfToppings);

                        string[] doughInfo = Console.ReadLine().Split(' ');

                        Dough dough = new Dough(doughInfo[1], doughInfo[2], double.Parse(doughInfo[3]));
                        pizza.Dough = dough;

                        for (int i = 0; i < numberOfToppings; i++)
                        {
                            string[] toppingInfo = Console.ReadLine().Split(' ');

                            Topping topping = new Topping(toppingInfo[1], double.Parse(toppingInfo[2]));

                            pizza.AddTopping(topping);
                        }

                        Console.WriteLine($"{pizza.Name} - {pizza.GetCalories():f2} Calories.");
                    }
                    else if (kind.ToLower() == "dough")
                    {
                        string flourType       = elements[1];
                        string bakingTechnique = elements[2];
                        double weight          = double.Parse(elements[3]);

                        Dough dough = new Dough(flourType, bakingTechnique, weight);

                        Console.WriteLine($"{dough.GetCalories():f2}");
                    }
                    else if (kind.ToLower() == "topping")
                    {
                        string type   = elements[1];
                        double weight = double.Parse(elements[2]);

                        Topping topping = new Topping(type, weight);

                        Console.WriteLine($"{topping.GetCalories():f2}");
                    }
                }
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #4
0
        private static void GetDough(List <string> listInputs)
        {
            string[] doughArgs = listInputs[0].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var      dough     = new Dough(doughArgs[1], doughArgs[2], double.Parse(doughArgs[3]));

            Console.WriteLine("{0:F2}", dough.GetCalories());
        }
Beispiel #5
0
 public double GetTotalCalories()
 {
     return(dough.GetCalories() + topings.Sum(x => x.GetCalories()));
 }