Beispiel #1
0
        private static void AddPizza(string[] tokens)
        {
            Pizza pizza = new Pizza(tokens[1], int.Parse(tokens[2]));

            tokens = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            Dough dough = new Dough(tokens[1], tokens[2], int.Parse(tokens[3]));

            pizza.Dough = dough;

            for (int i = 0; i < pizza.ToppingsCount; i++)
            {
                tokens = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                Topping top = new Topping(tokens[1], int.Parse(tokens[2]));
                pizza.AddToppingToPizza(top);
            }

            Console.WriteLine(pizza.ToString());
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            try
            {
                string[] pizzaArgs = Console.ReadLine().Split();

                string pizzaName = pizzaArgs[1];

                string[] doughArgs = Console.ReadLine().Split();

                string doughFlourType       = doughArgs[1];
                string doughBakingTechnique = doughArgs[2];
                double weight = double.Parse(doughArgs[3]);

                Dough dough = new Dough(doughFlourType, doughBakingTechnique, weight);

                Pizza pizza = new Pizza(pizzaName, dough);

                string inputLine = Console.ReadLine();

                while (inputLine != "END")
                {
                    string[] toppingArgs = inputLine.Split();

                    string toppingType   = toppingArgs[1];
                    double weightTopping = double.Parse(toppingArgs[2]);

                    Topping topping = new Topping(toppingType, weightTopping);

                    pizza.AddTopping(topping);

                    inputLine = Console.ReadLine();
                }

                Console.WriteLine($"{pizza.Name} - {pizza.GetTotalCalories().ToString("f2")} Calories.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Pizza pizza = new Pizza();

            while (true)
            {
                string[] input = Console.ReadLine().Split();
                if (input[0] == "END")
                {
                    break;
                }

                if (input[0] == "Pizza")
                {
                    pizza.Name = input[1];
                }
                else if (input[0] == "Dough")
                {
                    string flour      = input[1].ToLower();
                    string bakingTech = input[2].ToLower();
                    int    weight     = int.Parse(input[3]);
                    Dough  dough      = new Dough(flour, bakingTech, weight);
                    pizza.Dough = dough;
                }
                else if (input[0] == "Topping")
                {
                    string   toppingType = input[1].ToLower();
                    int      weight      = int.Parse(input[2]);
                    Toppings topping     = new Toppings(toppingType, weight);
                    pizza.Add(topping);
                    if (pizza.Toppings.Count > 10)
                    {
                        Exception ex = new ArgumentException("Number of toppings should be in range [0..10].");
                        Console.WriteLine(ex.Message);
                        Environment.Exit(0);
                    }
                }
            }

            Console.WriteLine(pizza);
        }
Beispiel #4
0
        public static void Main()
        {
            Dough   dough;
            Topping topping;
            Pizza   pizza;

            try
            {
                var pizzaInfo = Console.ReadLine().Split(" ".ToCharArray()).ToArray();
                var pizzaName = pizzaInfo[1];
                pizza = new Pizza(pizzaName);

                var doughInfo       = Console.ReadLine().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();
                var flourType       = doughInfo[1];
                var bakingTechnique = doughInfo[2];
                var weight          = double.Parse(doughInfo[3]);
                dough       = new Dough(flourType.ToLower(), bakingTechnique.ToLower(), weight);
                pizza.Dough = dough;

                string toppingInfo;
                while ((toppingInfo = Console.ReadLine()) != "END")
                {
                    string[] toppingParams = toppingInfo.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();

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

                    pizza.AddTopping(topping);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            Console.WriteLine(pizza);
        }
Beispiel #5
0
        public static void Main()
        {
            try
            {
                string[] nameInput = Console.ReadLine().Split();
                string   name      = nameInput[1];

                string[] doughInformation = Console.ReadLine().Split();
                string   flourType        = doughInformation[1];
                string   bakingTechnique  = doughInformation[2];
                double   weight           = double.Parse(doughInformation[3]);

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

                Pizza pizza = new Pizza(name, dough);

                string toppingInformation = Console.ReadLine();
                while (toppingInformation != "END")
                {
                    string[] parts = toppingInformation.Split();
                    string   type  = parts[1];
                    weight = double.Parse(parts[2]);

                    Topping topping = new Topping(type, weight);
                    pizza.AddTopping(topping);

                    toppingInformation = Console.ReadLine();
                }

                Console.WriteLine(pizza);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #6
0
 public Pizza(string name, Dough dough)
 {
     this.Name     = name;
     this.Dough    = dough;
     this.toppings = new List <Topping>();
 }
Beispiel #7
0
        public static void Main()
        {
            string command = Console.ReadLine();

            while (command != "END")
            {
                string[] tokens = command.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (tokens[0] == "Dough")
                {
                    try
                    {
                        Dough dough = new Dough(tokens[1], tokens[2], int.Parse(tokens[3]));
                        Console.WriteLine($"{dough.CalculateCalories():F2}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        return;
                    }
                }
                else if (tokens[0] == "Topping")
                {
                    try
                    {
                        Topping topping = new Topping(tokens[1], int.Parse(tokens[2]));
                        Console.WriteLine($"{topping.CalculateCalories():F2}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        return;
                    }
                }
                else
                {
                    string name             = tokens[1];
                    int    numberOfToppings = int.Parse(tokens[2]);

                    command = Console.ReadLine();
                    tokens  = command.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    Pizza pizza;
                    try
                    {
                        Dough dough = new Dough(tokens[1], tokens[2], int.Parse(tokens[3]));
                        pizza = new Pizza(name, dough);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        return;
                    }

                    for (int i = 0; i < numberOfToppings; i++)
                    {
                        command = Console.ReadLine();
                        tokens  = command.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        try
                        {
                            Topping topping = new Topping(tokens[1], int.Parse(tokens[2]));
                            pizza.AddTopping(topping);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            return;
                        }
                    }
                    Console.WriteLine($"{pizza.Name} - {pizza.GetCalories():F2} Calories.");
                    return;
                }
                command = Console.ReadLine();
            }
        }
Beispiel #8
0
        private static void AddDough(string[] tokens)
        {
            Dough dough = new Dough(tokens[1], tokens[2], int.Parse(tokens[3]));

            Console.WriteLine($"{dough.CalculateDoughCalories():f2}");
        }
Beispiel #9
0
        public static void Main()
        {
            var pizza = new Pizza();
            var dough = new Dough();

            var line = Console.ReadLine();

            if (line.Contains("Dough"))
            {
                var tokens = line
                             .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                             .ToArray();

                var type   = tokens[1];
                var tech   = tokens[2];
                var weight = double.Parse(tokens[3]);

                try
                {
                    dough = new Dough(type, tech, weight);
                    Console.WriteLine($"{dough.GetCalculateCalories():F2}");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return;
                }

                line = Console.ReadLine();

                if (line.Equals("END"))
                {
                    return;
                }
            }

            if (line.Contains("Topping"))
            {
                var tokens = line
                             .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                             .ToArray();

                var toppingName   = tokens[1];
                var toppingWeight = double.Parse(tokens[2]);

                try
                {
                    var topping = new Topping(toppingName, toppingWeight);
                    Console.WriteLine($"{topping.GetCalculateCalories():F2}");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return;
                }

                return;
            }

            while (line != "END")
            {
                var lineTokens = line
                                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                 .ToArray();

                switch (lineTokens[0])
                {
                case "Pizza":
                    var name         = lineTokens[1];
                    var toppingCount = int.Parse(lineTokens[2]);

                    try
                    {
                        pizza = new Pizza(name, toppingCount);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        return;
                    }

                    break;

                case "Dough":
                    var type   = lineTokens[1];
                    var tech   = lineTokens[2];
                    var weight = double.Parse(lineTokens[3]);

                    try
                    {
                        dough       = new Dough(type, tech, weight);
                        pizza.Dough = dough;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        return;
                    }

                    break;

                case "Topping":
                    var toppingName   = lineTokens[1];
                    var toppingWeight = double.Parse(lineTokens[2]);

                    try
                    {
                        var topping = new Topping(toppingName, toppingWeight);
                        pizza.Toppings.Add(topping);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        return;
                    }

                    break;
                }

                line = Console.ReadLine();
            }

            Console.WriteLine($"{pizza.Name} - {pizza.GetCalculateCalories():F2} Calories.");
        }