public static void Main() { var toppingsCount = 0; var pizza = new Pizza(); var totalCalories = 0.0; try { var pizzaArgs = Console.ReadLine().Split(); var pizzaName = pizzaArgs[1]; pizza.Name = pizzaName; pizzaArgs = Console.ReadLine().Split(); while (pizzaArgs[0] != "END") { var ingredientType = pizzaArgs[0]; if (ingredientType == "Dough") { var flourType = pizzaArgs[1]; var bakingTechnique = pizzaArgs[2]; var weight = double.Parse(pizzaArgs[3]); var dough = new Dough(flourType, bakingTechnique, weight); totalCalories += dough.CalculateCalories(); pizza.Dough = dough; } else if (ingredientType == "Topping") { var toppingType = pizzaArgs[1]; var weight = double.Parse(pizzaArgs[2]); var topping = new Topping(toppingType, weight); totalCalories += topping.CalculateCalories(); pizza.Toping.Add(topping); toppingsCount++; } pizzaArgs = Console.ReadLine().Split(); } } catch (Exception e) { Console.WriteLine(e.Message); return; } if (toppingsCount > 10) { Console.WriteLine("Number of toppings should be in range [0..10]."); return; } PrintResult(pizza, totalCalories); }
public static void MakePizza(string[] tokens) { var numberToppings = int.Parse(tokens[2]); var pizza = new Pizza(tokens[1], numberToppings); var doughInfo = Console.ReadLine().Split(' '); var dough = new Dough(doughInfo[1], doughInfo[2], double.Parse(doughInfo[3])); pizza.Dough = dough; for (var i = 0; i < numberToppings; i++) { var topInfo = Console.ReadLine().Split(' '); var topping = new Topping(topInfo[1], double.Parse(topInfo[2])); pizza.AddTopping(topping); } Console.WriteLine($"{pizza.Name} - {pizza.GetCalories():f2} Calories."); }
public void AddTopping(Topping topping) { this.toppings.Add(topping); }