public void AddTopping(Topping topping) { if(this.toppings.Count == 10) { throw new ArgumentException("Number of toppings should be in range [0..10]."); } this.toppings.Add(topping); }
private static void ReadAndAddTopping(Pizza pizza) { string command; while ((command = Console.ReadLine()) != "END") { var toppingTokens = command.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); var type = toppingTokens[1]; var weight = double.Parse(toppingTokens[2]); var topping = new Topping(type, weight); pizza.AddNewTopping(topping); } }
private static void PrintPizzaCalories(Queue <string> commands) { Pizza pizza = new Pizza(); while (commands.Count > 0) { string command = commands.Dequeue(); string[] inputArgs = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); switch (inputArgs[0]) { case "Pizza": string pizzaName = inputArgs[1]; int toppings = int.Parse(inputArgs[2]); pizza.Name = pizzaName; pizza.NumberOFToppings = toppings; break; case "Dough": string flourType = inputArgs[1]; string bakingTechnique = inputArgs[2]; double doughWeight = double.Parse(inputArgs[3]); Dough dough = new Dough(flourType, bakingTechnique, doughWeight); pizza.Dough = dough; break; case "Topping": string toppingsType = inputArgs[1]; double toppingsWeight = double.Parse(inputArgs[2]); Topping topping = new Topping(toppingsType, toppingsWeight); pizza.AddTopping(topping); break; default: break; } } double totalCalories = pizza.CalculateCalories(); Console.WriteLine($"{pizza.Name} - {totalCalories:f2} Calories."); }
private static void MakePizza(string[] tokens) { var pizzaName = tokens[1]; var numberOfToppings = int.Parse(tokens[2]); var pizza = new Pizza(pizzaName, numberOfToppings); var doughInput = Console.ReadLine().Split(); var dough = new Dough(doughInput[1], doughInput[2], double.Parse(doughInput[3])); pizza.Dough = dough; for (int i = 0; i < numberOfToppings; i++) { var toppingInput = Console.ReadLine().Split(); var toppingType = toppingInput[1]; var toppingWeight = double.Parse(toppingInput[2]); var topping = new Topping(toppingType, toppingWeight); pizza.AddTopping(topping); } Console.WriteLine($"{pizza.Name} - {pizza.CalculateCalories():f2} Calories."); }
public static void Main() { var input = Console.ReadLine(); try { while (input != "END") { var tokens = input.Split(); switch (tokens[0].ToLower()) { case "dough": var flourType = tokens[1]; var bakingTechnique = tokens[2]; var doughWeight = double.Parse(tokens[3]); var dough = new Dough(flourType, bakingTechnique, doughWeight); Console.WriteLine($"{dough.CalculateCalories():f2}"); break; case "topping": var toppingType = tokens[1]; var toppingWeight = double.Parse(tokens[2]); var topping = new Topping(toppingType, toppingWeight); Console.WriteLine($"{topping.CalculateCalories():f2}"); break; case "pizza": MakePizza(tokens); break; } input = Console.ReadLine(); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } }
private static void CalculatePizzaCalories() { var inpit = Console.ReadLine().Split(); try { while (inpit[0] != "END") { switch (inpit[0].ToLower()) { case "pizza": var pizza = SetPizza(inpit[1], int.Parse(inpit[2])); Console.WriteLine(pizza.GetTotalCalories()); break; case "dough": var douugh = new Dough(inpit[1], inpit[2], int.Parse(inpit[3])); Console.WriteLine($"{douugh.GetCalories():F2}"); break; case "topping": var toppint = new Topping(inpit[1], int.Parse(inpit[2])); Console.WriteLine($"{toppint.GetCalories():F2}"); break; default: break; } inpit = Console.ReadLine().Split(); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } }
//=========================== #region Methods public void AddTopping(Topping topping) { this.topping.Add(topping); }
public void AddTopping(Topping newTopping) { this.toppings.Add(newTopping); this.TotalTopings = this.toppings.Count(); }
public void AddTopping(Topping topping) { this.toppings.Enqueue(topping); this.NumberOfToppings = this.toppings.Count; }
private static void Main() { try { string line = Console.ReadLine(); if (line.StartsWith("Pizza")) { string[] pizzaLine = line.Split(); string[] doughLine = Console.ReadLine().Split(); Pizza newPizza = new Pizza(pizzaLine[1]); // Read all toppings while (true) { string cmd = Console.ReadLine(); if (cmd == "END") { break; } string[] toppingLine = cmd.Split(); newPizza.AddTopping(new Topping(toppingLine[1], int.Parse(toppingLine[2]))); } newPizza.Dough = new Dough(doughLine[1], doughLine[2], int.Parse(doughLine[3])); Console.WriteLine($"{newPizza.Name} - {newPizza.TotalCalories:f2} Calories."); } if (line.StartsWith("Dough")) { string[] doughLine = line.Split(); Dough newDough = new Dough(doughLine[1], doughLine[2], int.Parse(doughLine[3])); Console.WriteLine($"{newDough.Calories:F2}"); while (true) { string cmd = Console.ReadLine(); if (cmd == "END") { break; } string[] toppingLine = cmd.Split(); Topping newTopping = new Topping(toppingLine[1], int.Parse(toppingLine[2])); Console.WriteLine($"{newTopping.Calories:F2}"); } } } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { string command = Console.ReadLine(); while (command != "END") { string[] tokens = command.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); if (tokens[0] == "Dough") { try { Dough dough = new Dough(tokens[1], tokens[2], int.Parse(tokens[3])); Console.WriteLine("{0:f2}", dough.Callories()); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } } else if (tokens[0] == "Topping") { try { Topping topping = new Topping(tokens[1], int.Parse(tokens[2])); Console.WriteLine("{0:f2}", topping.Callories()); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } } else { string name = tokens[1]; int numberOfToppings = 0; numberOfToppings = int.Parse(tokens[2]); if (numberOfToppings > 10) { Console.WriteLine("Number of toppings should be in range [0..10]."); return; } command = Console.ReadLine(); tokens = command.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); Pizza pizza; try { Dough dough = new Dough(tokens[1], tokens[2], int.Parse(tokens[3])); pizza = new Pizza(name, dough); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } for (int i = 0; i < numberOfToppings; i++) { command = Console.ReadLine(); tokens = command.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); try { Topping topping = new Topping(tokens[1], int.Parse(tokens[2])); pizza.AddTopping(topping); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } } Console.WriteLine("{0} - {1:F2} Calories.", pizza.Name, pizza.Callories()); return; } command = Console.ReadLine(); } }
static void Main(string[] args) { string command = Console.ReadLine(); while (command != "END") { string[] tokens = command.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); if (tokens[0] == "Dough") { try { Dough dough = new Dough(tokens[1], tokens[2], int.Parse(tokens[3])); Console.WriteLine("{0:f2}", dough.Callories()); } catch(Exception ex) { Console.WriteLine(ex.Message); return; } } else if (tokens[0] == "Topping") { try { Topping topping = new Topping(tokens[1], int.Parse(tokens[2])); Console.WriteLine("{0:f2}", topping.Callories()); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } } else { string name = tokens[1]; int numberOfToppings = 0; numberOfToppings = int.Parse(tokens[2]); if (numberOfToppings > 10) { Console.WriteLine("Number of toppings should be in range [0..10]."); return; } command = Console.ReadLine(); tokens = command.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); Pizza pizza; try { Dough dough = new Dough(tokens[1], tokens[2], int.Parse(tokens[3])); pizza = new Pizza(name, dough); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } for (int i = 0; i < numberOfToppings; i++) { command = Console.ReadLine(); tokens = command.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); try { Topping topping = new Topping(tokens[1], int.Parse(tokens[2])); pizza.AddTopping(topping); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } } Console.WriteLine("{0} - {1:F2} Calories.", pizza.Name, pizza.Callories()); return; } command = Console.ReadLine(); } }