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 doughBackingTechnique = doughArgs[2]; double weight = double.Parse(doughArgs[3]); Dough dough = new Dough(doughFlourType, doughBackingTechnique, 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); } }
private static void AddTopping(Pizza pizza) { while (true) { var toppingInfo = Console.ReadLine().Split(); if (toppingInfo[0] == "END") { break; } var toppingType = toppingInfo[1]; var toppingWeight = int.Parse(toppingInfo[2]); var topping = new Topping(toppingType, toppingWeight); pizza.AddTopping(topping); } }
static void Main(string[] args) { var pizza = Console.ReadLine().Split(" ").ToArray(); var doughInput = Console.ReadLine().Split(" ").ToArray(); var dough = new Dough(doughInput[1], doughInput[2], decimal.Parse(doughInput[3])); var myPizza = new Pizza(pizza[1], dough); var input = Console.ReadLine(); while (input != "END") { var currentInput = input.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray(); var topping = new Topping(currentInput[1], decimal.Parse(currentInput[2])); myPizza.Add(topping); input = Console.ReadLine(); } Console.WriteLine(myPizza); }