Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            try
            {
                string inputLine;
                while (!(inputLine = Console.ReadLine()).Equals("END"))
                {
                    var tokens = inputLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    if (tokens[0].Equals("Dough"))
                    {
                        var dough = new Dough(tokens[1], tokens[2], int.Parse(tokens[3]));
                        Console.WriteLine($"{dough.Calories():f2}");
                    }
                    else if (tokens[0].Equals("Topping"))
                    {
                        var topping = new Topping(tokens[1], int.Parse(tokens[2]));
                        Console.WriteLine($"{topping.Callories():f2}");
                    }
                    else
                    {
                        var pizzaName        = tokens[1];
                        var numberOfToppings = int.Parse(tokens[2]);
                        if (numberOfToppings > 10)
                        {
                            Console.WriteLine("Number of toppings should be in range [0..10].");
                            return;
                        }

                        inputLine = Console.ReadLine();
                        var tokensDough = inputLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        var dough       = new Dough(tokensDough[1], tokensDough[2], int.Parse(tokensDough[3]));
                        var pizza       = new Pizza(pizzaName, dough);

                        for (int i = 0; i < numberOfToppings; i++)
                        {
                            inputLine = Console.ReadLine();
                            var tokenTopping = inputLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            pizza.AddToppind(new Topping(tokenTopping[1], int.Parse(tokenTopping[2])));
                        }

                        Console.WriteLine($"{pizza.Name} - {pizza.Callories():f2} Calories.");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 2
0
        private static void GetPizza(Pizza pizza)
        {
            while (true)
            {
                string input = Console.ReadLine();

                if (input == "END")
                {
                    break;
                }

                string[] hold = input.Split();

                string comand = hold[0];

                if (comand == "Pizza")
                {
                    pizza.Name = hold[1];
                }
                else if (comand == "Dough")
                {
                    string curentFlouer  = hold[1];
                    string curentBaking  = hold[2];
                    double curentDoughGr = double.Parse(hold[3]);

                    Dough holdDough = new Dough(curentFlouer, curentBaking, curentDoughGr);

                    pizza.Dough = holdDough;
                }
                else
                {
                    string curentType = hold[1];
                    double curentGr   = double.Parse(hold[2]);

                    Topping curentTopping = new Topping(curentType, curentGr);

                    pizza.Toppings.Add(curentTopping);

                    if (pizza.Toppings.Count > 10)
                    {
                        Console.WriteLine($"Number of toppings should be in range [0..10].");
                        Environment.Exit(0);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static void MakePizza(string[] tokens)
        {
            var numberToppings = int.Parse(tokens[2]);
            var pizza          = new Pizza(tokens[1], numberToppings);
            var doughInfo      = Console.ReadLine().Split(' ');
            var dough          = new Dough(doughInfo[1], doughInfo[2], double.Parse(doughInfo[3]));

            pizza.Dough = dough;

            for (var i = 0; i < numberToppings; i++)
            {
                var topInfo = Console.ReadLine().Split(' ');
                var topping = new Topping(topInfo[1], double.Parse(topInfo[2]));
                pizza.AddTopping(topping);
            }

            Console.WriteLine($"{pizza.Name} - {pizza.GetCalories():f2} Calories.");
        }
Exemplo n.º 4
0
 public void AddToppind(Topping topping)
 {
     this.Toppings.Add(topping);
 }