Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2016
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.30 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 _05_PizzaCalories
  8. {
  9. public class Dough
  10. {
  11. private string flourType;
  12. private string bakingTechnique;
  13. private double weight;
  14.  
  15. public Dough(string flourType, string bakingTechnique, double weight)
  16. {
  17. this.FlourType = flourType;
  18. this.BakingTechnique = bakingTechnique;
  19. this.Weight = weight;
  20. }
  21.  
  22. public string FlourType
  23. {
  24. get { return this.flourType; }
  25. set
  26. {
  27. if (value.ToLower() != "white" && value.ToLower() != "wholegrain")
  28. {
  29. throw new ArgumentException("Invalid type of dough.");
  30. }
  31. this.flourType = value;
  32. }
  33. }
  34.  
  35. public double Weight
  36. {
  37. get { return this.weight; }
  38. set
  39. {
  40. if (value < 1 || value > 200)
  41. {
  42. throw new ArgumentException("Dough weight should be in the range [1..200].");
  43. }
  44. this.weight = value;
  45. }
  46. }
  47.  
  48. public string BakingTechnique
  49. {
  50. get { return this.bakingTechnique; }
  51. set
  52. {
  53. if (value.ToLower() != "crispy" && value.ToLower() != "chewy" && value.ToLower() != "homemade")
  54. {
  55. throw new ArgumentException("Invalid type of dough.");
  56. }
  57. this.bakingTechnique = value;
  58. }
  59. }
  60.  
  61. public double CalculateCalories(Dough testo)
  62. {
  63. return Calculation(testo);
  64.  
  65. }
  66. private double Calculation(Dough testo)
  67. {
  68. //2 Калории на грам по дехфолт
  69. string flourType = testo.flourType;
  70. double weight = testo.weight;
  71. string bakingTechnique = testo.bakingTechnique;
  72. double calories = 2 * weight;
  73.  
  74. switch (flourType.ToLower())
  75. {
  76. case "white": calories *= 1.5; break;
  77. case "wholegrain": calories *= 1.0; break;
  78. }
  79.  
  80. switch (bakingTechnique.ToLower())
  81. {
  82. case "crispy": calories *= 0.9; break;
  83. case "chewy": calories *= 1.1; break;
  84. case "homemade": calories *= 1.0; break;
  85. }
  86.  
  87. return calories;
  88. }
  89. }
  90.  
  91. public class Pizza
  92. {
  93. private string pizzaName;
  94. private Dough testo;
  95. private List<Topping> toppingList;
  96. private int numberOfToppings;
  97. private double totalCalories;
  98.  
  99. public Pizza()
  100. {
  101. }
  102. public Pizza(string pizzaName)
  103. {
  104. this.PizzaName = pizzaName;
  105. this.Testo = testo;
  106. this.toppingList = new List<Topping>();
  107. this.NumberOfToppings = numberOfToppings;
  108. this.TotalCalories = totalCalories;
  109. }
  110.  
  111. public string PizzaName
  112. {
  113. get
  114. {
  115. return this.pizzaName;
  116. }
  117. set
  118. {
  119. if (value.Length < 15 && String.IsNullOrEmpty(value))
  120. {
  121. throw new ArgumentException("Pizza name should be between 1 and 15 symbols.");
  122. }
  123. this.pizzaName = value;
  124. }
  125. }
  126. public Dough Testo
  127. {
  128. get
  129. {
  130. return this.testo;
  131. }
  132.  
  133. set
  134. {
  135. this.testo = value;
  136. }
  137. }
  138. public int NumberOfToppings
  139. {
  140. get
  141. {
  142. return this.numberOfToppings;
  143. }
  144. set
  145. {
  146. if (value < 0 || value > 10)
  147. {
  148. throw new ArgumentException("Number of toppings should be in range [0..10].");
  149. }
  150. this.numberOfToppings = value;
  151. }
  152. }
  153.  
  154.  
  155. //public List<Topping> AddingTopings(Topping topping)
  156. //{
  157. // this.toppingList.Add(topping);
  158. // return this.toppingList;
  159. //}
  160.  
  161. public double TotalCalories
  162. {
  163. get
  164. {
  165. return this.totalCalories;
  166. }
  167. set
  168. {
  169. this.totalCalories = value;
  170. }
  171. }
  172. }
  173.  
  174. public class Topping
  175. {
  176. private string toppingName;
  177. private double toppingWeight;
  178.  
  179. public Topping(string toppingName, double toppingWeight)
  180. {
  181. this.ToppingName = toppingName;
  182. this.ToppingWeight = toppingWeight;
  183. }
  184.  
  185. public string ToppingName
  186. {
  187. get
  188. {
  189. return this.toppingName;
  190. }
  191. set
  192. {
  193. if (value.ToLower() != "meat" && value.ToLower() != "veggies" && value.ToLower() != "cheese" && value.ToLower() != "sauce")
  194. {
  195. throw new ArgumentException(string.Format("Cannot place {0} on top of your pizza.", value));
  196. }
  197. this.toppingName = value;
  198. }
  199. }
  200. public double ToppingWeight
  201. {
  202. get
  203. {
  204. return this.toppingWeight;
  205. }
  206. set
  207. {
  208. if (value < 1 || value > 50)
  209. {
  210. throw new ArgumentException(string.Format("{0} weight should be in the range [1..50].", this.toppingName));
  211. }
  212. this.toppingWeight = value;
  213. }
  214. }
  215.  
  216. public double CalculateCalories(Topping topping)
  217. {
  218. return Calculation(topping);
  219.  
  220. }
  221. private double Calculation(Topping topping)
  222. {
  223. string toppingName = topping.toppingName;
  224. double weight = topping.toppingWeight;
  225.  
  226. double calories = 2 * weight; //2 Калории на грам по дехфолт
  227.  
  228. switch (toppingName.ToLower())
  229. {
  230. case "meat": calories *= 1.2; break;
  231. case "veggies": calories *= 0.8; break;
  232. case "cheese": calories *= 1.1; break;
  233. case "sauce": calories *= 0.9; break;
  234. }
  235.  
  236. return calories;
  237. }
  238.  
  239. }
  240. public class Program
  241. {
  242. static void Main(string[] args)
  243. {
  244. string input = Console.ReadLine();
  245. var pizza = new Pizza();
  246.  
  247. while (input != "END")
  248. {
  249. string[] data = input.Split();
  250.  
  251. if (data[0] == "Pizza")
  252. {
  253. string pizzaName = data[1];
  254. int numberOfToppings = int.Parse(data[2]);
  255.  
  256. try
  257. {
  258. pizza.PizzaName = pizzaName;
  259. pizza.NumberOfToppings = numberOfToppings;
  260. }
  261. catch (ArgumentException ae)
  262. {
  263. Console.WriteLine(ae.Message);
  264. Environment.Exit(0);
  265. }
  266.  
  267. }
  268. else if (data[0] == "Dough")
  269. {
  270. string keyWord = data[0];
  271. string flourType = data[1];
  272. string bakeTech = data[2];
  273. double weight = double.Parse(data[3]);
  274. try
  275. {
  276. var testo = new Dough(flourType, bakeTech, weight);
  277.  
  278. pizza.Testo = testo;
  279. pizza.TotalCalories += (testo.CalculateCalories(testo));
  280. Console.WriteLine("{0:f2}", testo.CalculateCalories(testo));
  281. }
  282. catch (ArgumentException ae)
  283. {
  284. Console.WriteLine(ae.Message);
  285. Environment.Exit(0);
  286. }
  287. }
  288. else if (data[0] == "Topping")
  289. {
  290. string toppingName = data[1];
  291. double toppingWeight = double.Parse(data[2]);
  292.  
  293. try
  294. {
  295. var topping = new Topping(toppingName, toppingWeight);
  296. // pizza.AddingTopings(topping);
  297.  
  298. pizza.TotalCalories += (topping.CalculateCalories(topping));
  299. Console.WriteLine("{0:f2}", topping.CalculateCalories(topping));
  300. }
  301. catch (ArgumentException ae)
  302. {
  303. Console.WriteLine(ae.Message);
  304. Environment.Exit(0);
  305. }
  306. }
  307.  
  308. input = Console.ReadLine();
  309. }
  310.  
  311. if (!string.IsNullOrEmpty(pizza.PizzaName))
  312. {
  313. Console.WriteLine("{0} – {1:f2} Calories.", pizza.PizzaName, pizza.TotalCalories);
  314. }
  315. }
  316. }
  317. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement