Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Pizza_Calories
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Nota bene: Here I work under the assumption that the data of ONLY ONE pizza will be entered.
- //If it turns out that numerous pizzas need to be processed, revision of this program will be needed.
- string pizzaName = Console.ReadLine().Split(' ')[1];
- Pizza thePizza = new Pizza(pizzaName);
- while (true)
- {
- string intro = Console.ReadLine();
- if (intro == "END")
- {
- break;
- }
- string[] inputTokens = intro.Split(' ');
- if (inputTokens[0].ToLower() == "dough")
- {
- string flourType = inputTokens[1];
- string bakingTechnique = inputTokens[2];
- decimal weight = decimal.Parse(inputTokens[3]);
- Dough currentDough = new Dough();
- currentDough.FlourType = flourType;
- currentDough.BakingTechnique = bakingTechnique;
- currentDough.Weight = weight;
- decimal currentDoughCalories = currentDough.CaloriesCalculator();
- thePizza.doughs.Add(currentDough);
- thePizza.AddCalories(currentDoughCalories);
- }else if(inputTokens[0].ToLower()=="topping")
- {
- string type = inputTokens[1];
- decimal weight = decimal.Parse(inputTokens[2]);
- Toppings currentTopping = new Toppings();
- currentTopping.Type = type;
- currentTopping.Weight = weight;
- decimal currentToppingCalories = currentTopping.CaloriesCalculator();
- thePizza.toppings.Add(currentTopping);
- thePizza.AddCalories(currentToppingCalories);
- }
- }
- if (thePizza.toppings.Count() > 10||thePizza.toppings.Count()<0)
- {
- throw new Exception("Number of toppings should be in range [0..10].");
- }else
- {
- Console.WriteLine($"{thePizza.Name} - {thePizza.GetTotalCalories():F2} Calories.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement