static void Main(string[] args)
        {
            try
            {
                string[] nameOfPizza = Console.ReadLine().Split();
                Pizza    pizza       = new Pizza(nameOfPizza[1]);

                string command = string.Empty;
                while ((command = Console.ReadLine()) != "END")
                {
                    string[] tokens     = command.Split();
                    string   ingredient = tokens[0].ToLower();
                    if (ingredient == "dough")
                    {
                        string flourType = tokens[1].ToLower();
                        string technique = tokens[2].ToLower();
                        double weight    = double.Parse(tokens[3]);
                        Dough  dough     = new Dough(flourType, technique, weight);


                        double totalCalories = dough.CalculateCalories();
                        //Console.WriteLine($"{totalCalories:f2}");

                        pizza.Dough = dough;
                        pizza.AddCalories(totalCalories);
                    }
                    else if (ingredient == "topping")
                    {
                        string toppingType = tokens[1];
                        double weight      = double.Parse(tokens[2]);

                        Topping topping = new Topping(toppingType, weight);

                        double totalCalories = topping.CalcualteCalories();
                        // Console.WriteLine($"{totalCalories:f2}");

                        pizza.AddTopping(topping);
                        pizza.AddCalories(totalCalories);
                    }
                }
                Console.WriteLine(pizza.ToString());
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //Pizza pizza;
            //Dough dough;

            try
            {
                var   pizzaParams = Console.ReadLine().Split();
                Pizza pizza       = new Pizza(pizzaParams[1]);

                var doughParams = Console.ReadLine().Split();
                var flourType   = doughParams[1];
                var bakingType  = doughParams[2];
                var weight      = double.Parse(doughParams[3]);

                Dough dough = new Dough(flourType.ToLower(), bakingType.ToLower(), weight);

                pizza.PizzaDough = dough;

                string input;

                while ((input = Console.ReadLine()) != "END")
                {
                    var toppingParams = input.Split();

                    var toppingName   = toppingParams[1].ToLower();
                    var toppingWeight = double.Parse(toppingParams[2]);
                    var topping       = new Topping(toppingName, toppingWeight);

                    pizza.AddTopping(topping);
                }

                Console.WriteLine(pizza);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            string[] pizzaInput   = Console.ReadLine().Split();
            string[] inputDough   = Console.ReadLine().Split();
            string[] inputTopping = Console.ReadLine().Split();
            try
            {
                string flourType       = inputDough[1].ToLower();
                string bakingTechnique = inputDough[2].ToLower();
                double weight          = double.Parse(inputDough[3]);
                var    dough           = new Dough(flourType, bakingTechnique, weight);

                string originalType  = inputTopping[1];
                string type          = inputTopping[1].ToLower();
                double toppingWeight = double.Parse(inputTopping[2]);
                var    topping       = new Topping(type, toppingWeight, originalType);

                string name  = pizzaInput[1];
                var    pizza = new Pizza(name, dough);
                pizza.AddTopping(topping);

                string input = Console.ReadLine();
                while (input != "END")
                {
                    string[] tokens = input.Split();
                    originalType  = tokens[1];
                    type          = tokens[1].ToLower();
                    toppingWeight = double.Parse(tokens[2]);
                    var currentTopping = new Topping(type, toppingWeight, originalType);
                    pizza.AddTopping(currentTopping);
                    input = Console.ReadLine();
                }
                double calories = pizza.CalculateCalories();
                Console.WriteLine($"{pizza.Name} - {calories:f2} Calories.".Trim());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Pizza  pizzas            = new Pizza();
            string input             = Console.ReadLine();
            bool   checkForExeptions = false;

            while (input != "END")
            {
                string[] comands = input.Split(new char[] { ' ' }).ToArray();

                if (comands[0] == "Dough")
                {
                    try
                    {
                        Dough dough = new Dough(comands[1], comands[2], decimal.Parse(comands[3]));
                        pizzas.Dough = dough;
                    }
                    catch (ArgumentException e)
                    {
                        Console.WriteLine(e.Message);
                        checkForExeptions = true;
                    }
                }
                else if (comands[0] == "Topping")
                {
                    try
                    {
                        Topping topping = new Topping(comands[1], decimal.Parse(comands[2]));
                        if (pizzas.Topings.Count <= 10)
                        {
                            pizzas.Topings.Add(topping);
                        }
                        else
                        {
                            checkForExeptions = true;
                            throw new ArgumentException("Number of toppings should be in range [0..10].");
                        }
                    }
                    catch (ArgumentException e)
                    {
                        Console.WriteLine(e.Message);
                        checkForExeptions = true;
                    }
                }
                else if (comands[0] == "Pizza")
                {
                    try
                    {
                        pizzas.Name = comands[1];
                    }
                    catch (ArgumentException e)
                    {
                        checkForExeptions = true;
                        Console.WriteLine(e.Message);
                    }
                }
                if (checkForExeptions)
                {
                    break;
                }

                input = Console.ReadLine();
            }

            if (!checkForExeptions)
            {
                Console.WriteLine($"{pizzas.Name} - {pizzas.TotalCalories:F2} Calories.");
            }
        }
Beispiel #5
0
 public Pizza(Topping topping)
 {
     Topings.Add(topping);
 }