Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            int      topingcount = 0;
            double   totalcal    = 0;
            Toppings topping     = new Toppings();
            Doughts  dought      = new Doughts();
            string   pizzatype   = Console.ReadLine();
            string   pizzaname   = pizzatype.Substring(6).Trim();

            if (String.IsNullOrEmpty(pizzaname))
            {
                Console.WriteLine("Pizza name should be between 1 and 15 symbols.");
                Environment.Exit(0);
            }
            if (pizzaname.Length > 15 || pizzaname.Length < 1)
            {
                Console.WriteLine("Pizza name should be between 1 and 15 symbols.");
                Environment.Exit(0);
            }
            while (true)
            {
                string[] Input = Console.ReadLine().Split();
                if (Input[0].ToLower() == "end")
                {
                    break;
                }
                if (Input[0].ToLower() == "dough")
                {
                    dought.Flour  = Input[1].ToLower();
                    dought.Baking = Input[2].ToLower();
                    dought.Grams  = double.Parse(Input[3]);
                    totalcal     += dought.Calories();
                }
                else if (Input[0].ToLower() == "topping")
                {
                    topping.Toping = Input[1].ToLower();
                    topping.Grams  = double.Parse(Input[2]);
                    totalcal      += topping.PutTopings();
                    topingcount++;
                    if (topingcount > 10)
                    {
                        Console.WriteLine("Number of toppings should be in range [0..10].");
                        Environment.Exit(0);
                    }
                }
            }
            Console.WriteLine(pizzaname + " - {0:f2} Calories.", totalcal);
        }
Ejemplo n.º 2
0
        public static void GetPizzaMenu()
        {
            int pizzaId = 0;

            while (pizzaId < 1)
            {
                Console.Clear();
                Console.WriteLine("Please select a pizza");
                PizzaMenu.PrintInMenu();
                Console.Write(">");

                var userInput = Console.ReadLine();

                if (!int.TryParse(userInput, out pizzaId) || !PizzaMenu.PizzaInMenu(pizzaId))
                {
                    Console.WriteLine("User input was not correct.");
                    Console.ReadKey();
                    continue;
                }

                var pizza = PizzaMenu.GetPizza(pizzaId);

                do
                {
                    Console.Clear();
                    Console.WriteLine("Choose a pizza dough (thin or thick)");
                    userInput = Console.ReadLine().ToLower();
                } while (userInput != "thin" && userInput != "thick");

                if (userInput == "thin")
                {
                    pizza.IsThin = true;
                }
                else
                {
                    pizza.IsThin = false;
                }

                userInput = "";
                do
                {
                    Console.Clear();
                    Console.WriteLine($"Pizza: {pizza}");
                    Console.WriteLine("Select additional toppings. Insert empty line if you want to add pizza to shopping cart.");
                    Toppings.PrintToppings();
                    Console.Write(">");
                    userInput = Console.ReadLine();
                    if (userInput == "")
                    {
                        break;
                    }

                    if (!int.TryParse(userInput, out var toppingId) || Toppings.GetToppingById(toppingId) == null)
                    {
                        Console.WriteLine("User input is not correct");
                        Console.ReadKey();
                        continue;
                    }

                    pizza.AddIngredient(toppingId);
                    Console.WriteLine("Topping added");
                    Console.ReadKey();
                } while (userInput != "");

                _cart.AddPizza(pizza);
            }

            Console.WriteLine("Pizza added to cart");
            Console.ReadLine();
        }