private static void AddToppingsToPizza(Pizza pizza) { string command; while ((command = Console.ReadLine()) != "END") { string[] toppingArgs = command .Split() .Skip(1) .ToArray(); string toppingType = toppingArgs[0]; double toppingWeight = double.Parse(toppingArgs[1]); Topping topping = new Topping(toppingType, toppingWeight); pizza.AddTopping(topping); } }
static void Main(string[] args) { try { string[] pizzaInfo = Console.ReadLine().Split(); string pizzaName = string.Empty; if (pizzaInfo.Length <= 1) { pizzaName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(pizzaInfo[0].ToLower()); } else { pizzaName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(pizzaInfo[1].ToLower()); } Pizza pizza = new Pizza(pizzaName); string[] doughtInfo = Console.ReadLine().Split(); string doughType = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(doughtInfo[1].ToLower()); string doughTechnique = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(doughtInfo[2].ToLower()); double doughWeight = double.Parse(doughtInfo[3]); Dough dough = new Dough(doughType, doughTechnique, doughWeight); pizza.Dough = dough; string[] toppingInfo = Console.ReadLine().Split(); while (toppingInfo[0] != "END") { string toppingType = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(toppingInfo[1].ToLower()); double toppingWeight = double.Parse(toppingInfo[2]); Topping topping = new Topping(toppingType, toppingWeight); pizza.AddTopping(topping); toppingInfo = Console.ReadLine().Split(); } Console.WriteLine($"{pizza.Name} - {pizza.TotalCalories:f2} Calories."); } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } }
static void Main(string[] args) { string pizzaInput = Console.ReadLine(); try { while (true) { var pizzaArgs = pizzaInput.Split(); string name = pizzaArgs[1]; string doughInput = Console.ReadLine(); var doughArgs = doughInput.Split(); var flour = doughArgs[1]; var tech = doughArgs[2]; var grams = int.Parse(doughArgs[3]); Dough dough = new Dough(flour, tech, grams); Pizza pizza = new Pizza(name, dough); string toppingsInput = Console.ReadLine(); while (true) { var toppingsArgs = toppingsInput.Split(); var type = toppingsArgs[1]; var toppingGrams = int.Parse(toppingsArgs[2]); Topping topping = new Topping(type, toppingGrams); pizza.AddTopping(topping); toppingsInput = Console.ReadLine(); if (toppingsInput == "END") { Console.WriteLine(pizza); return; } } } } catch (Exception ae) { Console.WriteLine(ae.Message); } }
public static void Main(string[] args) { var pizzaName = Console.ReadLine().Split()[1]; //Сплитваме по спейс и след това взимаме втория елемент[1]; var doughData = Console.ReadLine().Split(); var flourType = doughData[1]; var bakingTechnique = doughData[2]; var weight = int.Parse(doughData[3]); try { var dough = new Dough(flourType, bakingTechnique, weight); var pizza = new Pizza(pizzaName, dough); while (true) { var line = Console.ReadLine(); if (line == "END") { break; } var parts = line.Split(); var toppingName = parts[1]; var toppingWeight = int.Parse(parts[2]); var topping = new Topping(toppingName, toppingWeight); pizza.AddTopping(topping); } Console.WriteLine($"{pizza.Name} - {pizza.GetCalories():F2} Calories."); } catch (Exception ex) when(ex is ArgumentException || ex is InvalidOperationException) { Console.WriteLine(ex.Message); } }
static void Main() { string[] pizzaInput = Console.ReadLine().Split(); string pizzaName = pizzaInput[1]; string[] doughInput = Console.ReadLine().Split(); string flourType = doughInput[1]; string backingTech = doughInput[2]; double weight = double.Parse(doughInput[3]); string command = Console.ReadLine(); try { Dough dough = new Dough(flourType, backingTech, weight); Pizza pizza = new Pizza(pizzaName, dough); while (command != "END") { string[] toppingInput = command.Split(); string type = toppingInput[1]; double toppingWeight = double.Parse(toppingInput[2]); Topping topping = new Topping(toppingWeight, type); pizza.AddTopping(topping); command = Console.ReadLine(); } Console.WriteLine($"{pizzaName} - {pizza.GetCallories():f2} Calories."); } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { try { var pizzaInfo = Console.ReadLine().Split(); var doughInfo = Console.ReadLine().Split(); var pizzaName = pizzaInfo[1]; var doughType = doughInfo[1]; var doughBacking = doughInfo[2]; var doughGrams = double.Parse(doughInfo[3]); var dough = new Dough(doughType, doughBacking, doughGrams); var pizza = new Pizza(pizzaName, dough); while (true) { var input = Console.ReadLine(); if (input == "END") { Console.WriteLine(pizza.ToString()); return; } var toppingInfo = input.Split(); var toppingType = toppingInfo[1]; var toppingGrams = double.Parse(toppingInfo[2]); var topping = new Topping(toppingType, toppingGrams); pizza.AddTopping(topping); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static void Main(string[] args) { try { string[] firstLine = Console.ReadLine().Split(); string pizzaName = firstLine[1]; string[] secondLine = Console.ReadLine().Split(); string flourType = secondLine[1]; string bakingTechnique = secondLine[2]; int doughWeight = int.Parse(secondLine[3]); Dough dough = new Dough(flourType, bakingTechnique, doughWeight); Pizza pizza = new Pizza(pizzaName, dough); string thirdLine = Console.ReadLine(); while (thirdLine != "END") { string[] arg = thirdLine.Split(); string toppingName = arg[1]; int toppingWeight = int.Parse(arg[2]); Topping topping = new Topping(toppingName, toppingWeight); pizza.AddToppings(topping); thirdLine = Console.ReadLine(); } Console.WriteLine($"{pizza.Name} - {pizza.PizzaCalories():f2} Calories."); } catch (Exception ex) when(ex is ArgumentException || ex is InvalidOperationException) { Console.WriteLine(ex.Message); } }
static void Main(string[] args) { try { string pizzaName = Console.ReadLine().Split()[1]; string[] doughInput = Console.ReadLine().Split(); string doughType = doughInput[1]; string bakingTechnique = doughInput[2]; int doughWeight = int.Parse(doughInput[3]); Dough dough = new Dough(doughType, bakingTechnique, doughWeight); Pizza pizza = new Pizza(pizzaName, dough); string[] toppingInput = Console.ReadLine().Split(); while (toppingInput[0] != "END") { string toppingType = toppingInput[1]; int toppingWeight = int.Parse(toppingInput[2]); Topping topping = new Topping(toppingType, toppingWeight); pizza.AddTopping(topping); toppingInput = Console.ReadLine().Split(); } Console.WriteLine($"{pizzaName} - {pizza.CalculateTotalCalories():F2} Calories."); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } // 92/100 }