public static void Main(string[] args) { try { string pizzaName = Console.ReadLine().Split()[1]; string[] doughInfo = Console.ReadLine().Split(); string doughType = doughInfo[1]; string doughTechnique = doughInfo[2]; decimal doughWeight = decimal.Parse(doughInfo[3]); Pizza pizza = new Pizza(pizzaName, new Dough(doughType, doughTechnique, doughWeight)); string toppingInfo = Console.ReadLine(); while (toppingInfo != "END") { string[] toppingInfoTokens = toppingInfo.Split(' ', StringSplitOptions.RemoveEmptyEntries); string type = toppingInfoTokens[1]; decimal weight = decimal.Parse(toppingInfoTokens[2]); Topping topping = new Topping(type, weight); pizza.AddTopping(topping); toppingInfo = Console.ReadLine(); } Console.WriteLine(pizza.ToString()); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } }
private static void PrintPizza(string input) { var pizzaData = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var pizzaName = pizzaData[1]; var toppingsCount = int.Parse(pizzaData[2]); if (toppingsCount < 0 || toppingsCount > 10) { throw new ArgumentException($"Number of toppings should be in range [0..10]."); } var doughData = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var flourType = doughData[1]; var technique = doughData[2]; var doughWeight = int.Parse(doughData[3]); Dough dough = new Dough(flourType, technique, doughWeight); Pizza pizza = new Pizza(pizzaName, dough); for (int i = 0; i < toppingsCount; i++) { var toppingTokens = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var toppingType = toppingTokens[1]; var toppingWeight = int.Parse(toppingTokens[2]); var topping = new Topping(toppingType, toppingWeight); pizza.AddTopping(topping); } Console.WriteLine(pizza.ToString()); }
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()); }