예제 #1
0
        static void Main(string[] args)
        {
            var    pizzaInput = Console.ReadLine().Split();
            string pizzaName  = pizzaInput[1];

            try
            {
                pizza = new Pizza(pizzaName);
            }
            catch (ArgumentException argEx)
            {
                Console.WriteLine(argEx.Message);
                return;
            }

            var    doughInput      = Console.ReadLine().Split();
            string doughType       = doughInput[1];
            string bakingTEchnique = doughInput[2];
            int    doughWeight     = int.Parse(doughInput[3]);

            try
            {
                Dough dough = new Dough(doughType, bakingTEchnique, doughWeight);
                pizza.Dough = dough;
            }
            catch (ArgumentException argEx)
            {
                Console.WriteLine(argEx.Message);
                return;
            }

            string command = Console.ReadLine();

            while (command != "END")
            {
                var    toppingInput  = command.Split();
                string toppingType   = toppingInput[1];
                int    toppingWeight = int.Parse(toppingInput[2]);

                try
                {
                    Topping topping = new Topping(toppingType, toppingWeight);
                    try
                    {
                        pizza.AddTopping(topping);
                    }
                    catch (ArgumentException argEx)
                    {
                        Console.WriteLine(argEx.Message);
                        return;
                    }
                }
                catch (ArgumentException argEx)
                {
                    Console.WriteLine(argEx.Message);
                    return;
                }
                command = Console.ReadLine();
            }

            Console.WriteLine(pizza);
        }
예제 #2
0
        public static void Main(string[] args)
        {
            var firstRow = Console.ReadLine().Split();

            if (firstRow[0].ToLower() == "pizza")
            {
                var           pizzaTokens = firstRow;
                Pizza         pizza;
                var           doughTokens  = Console.ReadLine().Split();
                List <string> toppingsList = new List <string>();
                var           input        = "";

                while ((input = Console.ReadLine()) != "END" || int.Parse(pizzaTokens[2]) == 0)
                {
                    toppingsList.Add(input);
                }

                try
                {
                    pizza = new Pizza(
                        pizzaTokens[1],
                        int.Parse(pizzaTokens[2]));
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                    return;
                }


                try
                {
                    pizza.Dough = new Dough(doughTokens[1].ToLower(), doughTokens[2], int.Parse(doughTokens[3]));
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                    return;
                }


                List <Topping> toppings = new List <Topping>();


                for (int i = 0; i < pizza.NumberOfToppings; i++)
                {
                    var toppingTokens = toppingsList[i].Split();
                    try
                    {
                        Topping topping = new Topping(toppingTokens[1], int.Parse(toppingTokens[2]));
                        toppings.Add(topping);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        return;
                    }
                }

                pizza.Toppings = toppings;

                Console.WriteLine($"{pizza.Name} - {pizza.TotalCalories():f2} Calories.");
            }

            else
            {
                var tokens = firstRow;

                while (tokens[0] != "END")
                {
                    if (tokens[0] == "Dough")
                    {
                        try
                        {
                            Dough dough = new Dough(tokens[1].ToLower(), tokens[2], int.Parse(tokens[3]));
                            Console.WriteLine($"{dough.Modifier():f2}");
                        }
                        catch (ArgumentException e)
                        {
                            Console.WriteLine(e.Message);
                            return;
                        }
                    }
                    else if (tokens[0] == "Topping")
                    {
                        try
                        {
                            Topping topping = new Topping(tokens[1], int.Parse(tokens[2]));
                            Console.WriteLine($"{topping.Modifier():f2}");
                        }
                        catch (ArgumentException e)
                        {
                            Console.WriteLine(e.Message);
                            return;
                        }
                    }

                    tokens = Console.ReadLine().Split();
                }
            }
        }
예제 #3
0
        public static void Main(string[] args)
        {
            var pizzaName = "";

            try
            {
                pizzaName = Console.ReadLine()
                            .Split(" ", StringSplitOptions.RemoveEmptyEntries)[1];
            }
            catch (Exception)
            {
                Console.WriteLine("Pizza name should be between 1 and 15 symbols.");
                return;
            }


            var doughInput = Console.ReadLine()
                             .Split(" ", StringSplitOptions.RemoveEmptyEntries);

            Dough dough = null;

            try
            {
                dough = new Dough(doughInput[1].ToLower(), doughInput[2].ToLower(), int.Parse(doughInput[3]));
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
            Pizza pizza = null;

            try
            {
                pizza = new Pizza(pizzaName, dough);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }


            var line = Console.ReadLine();

            while (line != "END")
            {
                var     splitTop = line.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                Topping topping  = null;
                try
                {
                    topping = new Topping(splitTop[1].ToLower(), int.Parse(splitTop[2]));
                    pizza.AddT(topping);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                    return;
                }

                line = Console.ReadLine();
            }

            //if (pizza.Topping.Count > 10)
            //{
            //    throw new ArgumentException("Number of toppings should be in range [0..10].");
            //}

            Console.WriteLine($"{pizza.Name} - {pizza.totalCalories():F2} Calories.");
        }
예제 #4
0
        public static void Main()
        {
            //75/100
            var pizza = new Pizza();
            var dough = new Dough();

            var inputLine = Console.ReadLine();

            if (inputLine.Contains("Dough"))
            {
                var tokens = inputLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var type   = tokens[1];
                var tech   = tokens[2];
                var weight = double.Parse(tokens[3]);

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

                inputLine = Console.ReadLine();
                if (inputLine.Equals("END"))
                {
                    return;
                }
            }

            if (inputLine.Contains("Topping"))
            {
                var tokens        = inputLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var toppingName   = tokens[1];
                var toppingWeight = double.Parse(tokens[2]);

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

                return;
            }


            while (!inputLine.Equals("END"))
            {
                var tokens = inputLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (tokens[0].Equals("Pizza"))
                {
                    var name = tokens[1];


                    try
                    {
                        pizza = new Pizza(name);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        return;
                    }
                }
                else if (tokens[0].Equals("Dough"))
                {
                    var type   = tokens[1];
                    var tech   = tokens[2];
                    var weight = double.Parse(tokens[3]);

                    try
                    {
                        dough       = new Dough(type, tech, weight);
                        pizza.Dough = dough;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        return;
                    }
                }
                else
                {
                    var toppingName   = tokens[1];
                    var toppingWeight = double.Parse(tokens[2]);

                    try
                    {
                        var topping = new Topping(toppingName, toppingWeight);
                        if (pizza.Toppings.Count < 10)
                        {
                            pizza.Toppings.Add(topping);
                        }
                        else
                        {
                            Console.WriteLine($"Number of toppings should be in range [0..10].");
                            return;
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        return;
                    }
                }

                inputLine = Console.ReadLine();
            }

            Console.WriteLine($"{pizza.Name} - {pizza.CalcCalories():f2} Calories.");
        }
예제 #5
0
        public static void Main()
        {
            string input = Console.ReadLine();

            while (!input.Equals("END"))
            {
                string[] args = input.Split();

                if (args[0].Equals("Dough"))
                {
                    try
                    {
                        Dough dough = new Dough(args[1], args[2], double.Parse(args[3]));
                        Console.WriteLine($"{dough.CalcDoughCalories():F2}");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        return;
                    }
                }
                else if (args[0].Equals("Topping"))
                {
                    try
                    {
                        Topping topping = new Topping(args[1], double.Parse(args[2]));
                        Console.WriteLine($"{topping.CalcToppingCalories():F2}");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        return;
                    }
                }
                else if (args[0].Equals("Pizza"))
                {
                    try
                    {
                        Pizza pizza = new Pizza(args[1], int.Parse(args[2]));
                        input = Console.ReadLine();
                        args  = input.Split();
                        Dough dough = new Dough(args[1], args[2], double.Parse(args[3]));
                        pizza.Dough = dough;

                        for (int i = 0; i < pizza.ToppingsCount; i++)
                        {
                            args = Console.ReadLine().Split();
                            pizza.AddToping(args[1], double.Parse(args[2]));
                        }

                        Console.WriteLine($"{pizza.Name} - {pizza.CalcTotalCalories():F2} Calories.");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        return;
                    }
                }

                input = Console.ReadLine();
            }
        }
예제 #6
0
        static void Main()
        {
            string command = Console.ReadLine();

            string[] commandArgs = command.ToLower().Split(' ', StringSplitOptions.RemoveEmptyEntries);

            if (commandArgs[0] == "pizza")
            {
                try
                {
                    Pizza pizza = new Pizza(commandArgs[1]);

                    command = Console.ReadLine();

                    while (command != "END")
                    {
                        commandArgs = command.ToLower().Split(' ', StringSplitOptions.RemoveEmptyEntries);

                        if (commandArgs[0] == "dough")
                        {
                            try
                            {
                                Dough dough = new Dough(commandArgs[1], commandArgs[2], double.Parse(commandArgs[3]));
                                pizza.Dough = dough;
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                                return;
                            }
                        }
                        else if (commandArgs[0] == "topping")
                        {
                            try
                            {
                                if (pizza.Toppings.Count >= 0 && pizza.Toppings.Count <= 10)
                                {
                                    Topping topping = new Topping(commandArgs[1], double.Parse(commandArgs[2]));
                                    pizza.Toppings.Add(topping);
                                }
                                else
                                {
                                    throw new ArgumentException("Number of toppings should be in range [0..10].");
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                                return;
                            }
                        }
                        command = Console.ReadLine();
                    }

                    char[]        pizzaArray = pizza.Name.ToCharArray();
                    StringBuilder sb         = new StringBuilder();
                    sb.Append(pizzaArray[0].ToString().ToUpper());
                    for (int i = 1; i < pizzaArray.Length; i++)
                    {
                        sb.Append(pizzaArray[i]);
                    }
                    Console.WriteLine($"{sb.ToString()} - {pizza.GetPizzaCalories():f2} Calories.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return;
                }
            }
        }
예제 #7
0
        static void Main(string[] args)

        {
            //        Pizza Meatless

            //Dough Wholegrain Crispy 100

            //Topping Veggies 50

            //Topping Cheese 50

            //END

            Pizza pizza;

            Dough dough;



            try

            {
                string[] pizzaInfo = Console.ReadLine().Split();

                string pizzaName = pizzaInfo[1];

                pizza = new Pizza(pizzaName);
            }

            catch (Exception e)

            {
                Console.WriteLine(e.Message);

                return;
            }



            try

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

                string flour = doughInfo[1];

                string bakingTech = doughInfo[2];

                double weight = double.Parse(doughInfo[3]);

                dough = new Dough(flour.ToLower(), bakingTech.ToLower(), weight);



                pizza.PizzaDough = dough;
            }

            catch (Exception e)

            {
                Console.WriteLine(e.Message);

                return;
            }



            string toppingInfo;



            while ((toppingInfo = Console.ReadLine()) != "END")

            {
                try

                {
                    string[] toppingParams = toppingInfo.Split();



                    string toppingName = toppingParams[1].ToLower();

                    double toppingWeight = double.Parse(toppingParams[2]);

                    Topping topping = new Topping(toppingName, toppingWeight);



                    pizza.Add(topping);
                }

                catch (Exception e)

                {
                    Console.WriteLine(e.Message);

                    return;
                }
            }



            try

            {
                Console.WriteLine($"{pizza.Name} - {pizza.PizzaCalories():f2} Calories.");
            }

            catch (Exception e)

            {
                Console.WriteLine(e.Message);

                return;
            }
        }