private static void Main() { var input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); try { while (!input[0].Equals("END")) { switch (input[0]) { case "Pizza": Pizza pizza = CreatePizza(input); Console.WriteLine($"{pizza.Name} - {pizza.GetTotalCalories():F2} Calories."); break; case "Dough": Dough dough = CreateDough(input); Console.WriteLine($"{dough.GetCalories():F2}"); break; case "Topping": Topping topping = CreateTopping(input); Console.WriteLine($"{topping.GetCalories():F2}"); break; } input = Console.ReadLine() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } }
public static void Main() { string input; while ((input = Console.ReadLine()) != "END") { var pizzaArgs = input.Split().Select(x => x.ToLower()).ToArray(); try { if (pizzaArgs[0] == "dough") { var doughCheck = new Dough(pizzaArgs[1], pizzaArgs[2], double.Parse(pizzaArgs[3])); Console.WriteLine($"{doughCheck.GetCalories():f2}"); } else if (pizzaArgs[0] == "topping") { var topping = new Topping(pizzaArgs[1], double.Parse(pizzaArgs[2])); Console.WriteLine($"{topping.GetCalories():f2}"); } else if (pizzaArgs[0] == "pizza") { var numberOfToppings = int.Parse(pizzaArgs[2]); if (numberOfToppings < 0 || numberOfToppings > 10) { throw new ArgumentException("Number of toppings should be in range [0..10]."); } var pizzaName = pizzaArgs[1]; var doughArgs = Console.ReadLine().Split().Select(x => x.ToLower()).ToArray(); var doughType = doughArgs[1]; var doughTech = doughArgs[2]; var doughWeight = double.Parse(doughArgs[3]); var dough = new Dough(doughType, doughTech, doughWeight); var pizza = new Pizza(pizzaName, dough); for (int i = 0; i < numberOfToppings; i++) { var toppingArgs = Console.ReadLine().Split().Select(x => x.ToLower()).ToArray(); var toppingType = toppingArgs[1]; var toppingWeight = double.Parse(toppingArgs[2]); var topping = new Topping(toppingType, toppingWeight); pizza.AddTopping(topping); } Console.WriteLine($"{pizza.Name} - {pizza.GetTotalCalories():F2} Calories."); } } catch (Exception e) { Console.WriteLine(e.Message); return; } } }
static void Main() { try { int numberOfToppings = 0; var tokens = Console.ReadLine().Split(); var pizza = new Pizza(tokens[1]); var line = string.Empty; while ((line = Console.ReadLine()) != "END") { tokens = line.Split(); if (tokens[0] == "Dough") { var dough = new Dough(tokens[1], tokens[2], double.Parse(tokens[3])); pizza.Dough = dough; } else { var topping = new Topping(tokens[1], double.Parse(tokens[2])); pizza.AddTopping(topping); numberOfToppings++; } } pizza.NumberOfToppings = numberOfToppings; Console.WriteLine($"{pizza.Name} - {pizza.GetTotalCalories():f2} Calories."); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Main() { var listInputs = new List <string>(); string input; while ((input = Console.ReadLine()) != "END") { listInputs.Add(input); } listInputs.Add("END"); try { switch (listInputs.Count) { case 2: GetDough(listInputs); break; case 3: GetDough(listInputs); string[] toppingArgs = listInputs[1].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var topping = new Topping(toppingArgs[1], double.Parse(toppingArgs[2])); Console.WriteLine("{0:F2}", topping.GetCalories()); break; default: string[] doughArgs = listInputs[1].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var dough = new Dough(doughArgs[1], doughArgs[2], double.Parse(doughArgs[3])); string[] pizzaArgs = listInputs[0].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var pizza = new Pizza(pizzaArgs[1], int.Parse(pizzaArgs[2]), dough); foreach (var line in listInputs.Skip(2)) { if (line == "END") { Console.WriteLine($"{pizza.Name} - {pizza.GetTotalCalories():F2} Calories."); break; } toppingArgs = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); pizza.AddTopping(new Topping(toppingArgs[1], double.Parse(toppingArgs[2]))); } break; } } catch (Exception e) { Console.WriteLine(e.Message); } }
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); } }