Advertisement
Guest User

Program

a guest
Nov 1st, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Pizza_Calories
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. //Nota bene: Here I work under the assumption that the data of ONLY ONE pizza will be entered.
  14. //If it turns out that numerous pizzas need to be processed, revision of this program will be needed.
  15. string pizzaName = Console.ReadLine().Split(' ')[1];
  16. Pizza thePizza = new Pizza(pizzaName);
  17. while (true)
  18. {
  19. string intro = Console.ReadLine();
  20. if (intro == "END")
  21. {
  22. break;
  23. }
  24. string[] inputTokens = intro.Split(' ');
  25. if (inputTokens[0].ToLower() == "dough")
  26. {
  27. string flourType = inputTokens[1];
  28. string bakingTechnique = inputTokens[2];
  29. decimal weight = decimal.Parse(inputTokens[3]);
  30. Dough currentDough = new Dough();
  31. currentDough.FlourType = flourType;
  32. currentDough.BakingTechnique = bakingTechnique;
  33. currentDough.Weight = weight;
  34. decimal currentDoughCalories = currentDough.CaloriesCalculator();
  35. thePizza.doughs.Add(currentDough);
  36. thePizza.AddCalories(currentDoughCalories);
  37. }else if(inputTokens[0].ToLower()=="topping")
  38. {
  39. string type = inputTokens[1];
  40. decimal weight = decimal.Parse(inputTokens[2]);
  41. Toppings currentTopping = new Toppings();
  42. currentTopping.Type = type;
  43. currentTopping.Weight = weight;
  44. decimal currentToppingCalories = currentTopping.CaloriesCalculator();
  45. thePizza.toppings.Add(currentTopping);
  46. thePizza.AddCalories(currentToppingCalories);
  47. }
  48. }
  49.  
  50. if (thePizza.toppings.Count() > 10||thePizza.toppings.Count()<0)
  51. {
  52. throw new Exception("Number of toppings should be in range [0..10].");
  53. }else
  54. {
  55. Console.WriteLine($"{thePizza.Name} - {thePizza.GetTotalCalories():F2} Calories.");
  56. }
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement