Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace RestaurantAssignment
  5. {
  6. public class Stock
  7. {
  8. public List<DrinkItem> Drinks { get; set; }
  9. public List<FoodItem> Foods { get; set; }
  10.  
  11. public Stock()
  12. {
  13. Drinks = new List<DrinkItem>();
  14. Foods = new List<FoodItem>();
  15.  
  16. }
  17.  
  18. public List<string> GetDrinkNames()
  19. {
  20. List<string> drinks = new List<string>();
  21.  
  22. foreach (var item in Drinks)
  23. {
  24. var name = item.Name;
  25.  
  26. // If the item is alcoholic, add alcoholic volume to item name
  27. if (item.IsAlcoholic())
  28. name = $"{name} ({item.GetAlcoholicVolume()}%)";
  29. // name = name + " (" + item.GetAlcoholicVolume() + "%)";
  30.  
  31. drinks.Add(name);
  32. }
  33.  
  34. return drinks;
  35. }
  36.  
  37. public List<string> GetFoodNames()
  38. {
  39. List<string> foods = new List<string>();
  40.  
  41. foreach (var item in Foods)
  42. {
  43. foods.Add(item.Name);
  44. }
  45.  
  46. return foods;
  47. }
  48.  
  49. public List<DrinkItem> GetAlcoholicDrinks()
  50. {
  51. List<DrinkItem> alcholicDrinks = new List<DrinkItem>();
  52.  
  53. foreach (var item in Drinks)
  54. {
  55. if (item.IsAlcoholic())
  56. alcholicDrinks.Add(item);
  57. }
  58.  
  59. return alcholicDrinks;
  60. }
  61.  
  62. public List<string> GetAlcoholicDrinkNames()
  63. {
  64. List<string> alcholicDrinkNames = new List<string>();
  65.  
  66. foreach (var item in Drinks)
  67. {
  68. if (item.IsAlcoholic())
  69. alcholicDrinkNames.Add(item.Name);
  70. }
  71.  
  72. return alcholicDrinkNames;
  73. }
  74.  
  75. // Assign total cost to all items on order
  76. public double TotalCost()
  77. {
  78. double runningTotal = 0;
  79.  
  80. foreach (var drink in Drinks)
  81. {
  82. runningTotal += drink.GetCost();
  83. }
  84.  
  85. foreach (var food in Foods)
  86. {
  87. runningTotal += food.GetCost();
  88. }
  89.  
  90. return runningTotal;
  91. }
  92.  
  93. // User creates new food item and assigns the appropriate number of servings
  94. public void AddFoodItem()
  95. {
  96. FoodItem food = new FoodItem();
  97. AddItem(food);
  98.  
  99. Console.WriteLine("Add number of servings");
  100. Console.Write("> ");
  101. var servings = Console.ReadLine();
  102.  
  103. food.SetNumberServed(Convert.ToInt32(servings));
  104.  
  105. Foods.Add(food);
  106.  
  107. using (StreamWriter sw = new StreamWriter("Drink_menu.txt", true))
  108.                         {
  109.                             sw.WriteLine(outputDrink);
  110.                         }
  111.  
  112. }
  113.  
  114. // User creates new drink and adds alcoholic volume
  115. public void AddDrinkItem()
  116. {
  117. DrinkItem drink = new DrinkItem();
  118. AddItem(drink);
  119.  
  120. Console.WriteLine("Enter alcoholic volume");
  121. Console.Write("> ");
  122. var alcoholic = Console.ReadLine();
  123.  
  124. drink.SetAlcoholicVolume(Convert.ToDouble(alcoholic));
  125.  
  126. Drinks.Add(drink);
  127. }
  128.  
  129. // User inputs name, description and price. This is then assigned to the item
  130. public void AddItem(Item item)
  131. {
  132. Console.WriteLine("Adding new item...");
  133. Console.WriteLine("Enter new item name");
  134.  
  135. Console.Write("> ");
  136. item.Name = Console.ReadLine();
  137.  
  138. Console.WriteLine("Enter new item description");
  139. Console.Write("> ");
  140. item.Description = Console.ReadLine();
  141.  
  142. Console.WriteLine("Enter new item price");
  143. Console.Write("> ");
  144. item.SetCost(Convert.ToDouble(Console.ReadLine()));
  145. }
  146. }
  147.  
  148. public class Item
  149. {
  150. public string Name;
  151. public string Description;
  152.  
  153. private double cost;
  154.  
  155. public Item()
  156. {
  157.  
  158. }
  159.  
  160. public double GetCost()
  161. {
  162. return cost;
  163. }
  164.  
  165. // SetCost ensures a valid cost is set
  166. public void SetCost(double newCost)
  167. {
  168. // Turnary statement, if new cost is less than or equal to 0
  169. // Set cost to 0, else set the cost to new cost
  170. cost = (newCost <= 0) ? 0 : newCost;
  171. }
  172. }
  173.  
  174. public class FoodItem : Item
  175. {
  176. private int numberServed;
  177.  
  178. public int GetNumberServed()
  179. {
  180. return numberServed;
  181. }
  182.  
  183. public void SetNumberServed(int servings)
  184. {
  185. // Check that servings does not exceed the maximum.
  186. if (servings < 0 || servings > 4)
  187. {
  188. return;
  189. }
  190.  
  191. numberServed = servings;
  192. }
  193.  
  194. public FoodItem(string name)
  195. {
  196. Name = name;
  197. }
  198.  
  199. public FoodItem()
  200. {
  201.  
  202. }
  203. }
  204.  
  205. // 1. AlcoholicVolume Property
  206. // 2. Getter and Setter for AlcoholicVolume
  207. // 3. Add validation to the AlcoholicVolume Setter
  208. // 4. Add a Constructor for Drink which takes a name
  209. // 5. Add IsAlcoholic() method, returning true if
  210. // AlcoholicVolume is > 0.
  211.  
  212. public class DrinkItem : Item
  213. {
  214.  
  215. private double AlcoholicVolume;
  216.  
  217. public double GetAlcoholicVolume()
  218. {
  219. return AlcoholicVolume;
  220. }
  221.  
  222. public void SetAlcoholicVolume(double volume)
  223. {
  224. // Check if level of alcohol is < 0
  225. if (AlcoholicVolume < 0)
  226. {
  227. return;
  228. }
  229.  
  230. AlcoholicVolume = volume;
  231. }
  232.  
  233. public DrinkItem(string name)
  234. {
  235. Name = name;
  236. }
  237.  
  238. public DrinkItem()
  239. {
  240.  
  241. }
  242.  
  243. public bool IsAlcoholic()
  244. {
  245. // Checks if alcoholic volume is > 0, if it is
  246. // return true
  247. return AlcoholicVolume > 0;
  248. }
  249. }
  250. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement