Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. namespace RestaurantAssignment
  5. {
  6. class Program
  7. {
  8.  
  9. static void PrintHelp()
  10. {
  11. Console.WriteLine("Welcome to Steve's Fishshop please select an option: ");
  12. Console.WriteLine("Select option 1 to add a food item... ");
  13. Console.WriteLine("Select option 2 to add a drink item...");
  14. Console.WriteLine("Select option 3 to print a list of current items...");
  15. Console.WriteLine("Select option 4 to edit exsisting records...");
  16. Console.WriteLine("Select option 5 to output the total cost... ");
  17. Console.WriteLine("Select option 6 to quit selection...");
  18. }
  19.  
  20. static void Main(string[] args)
  21. {
  22. Stock stockList = new Stock();
  23.  
  24. // Adding food and drink items to start the list
  25. //stockList.Foods.Add(new FoodItem { Name = "Cod and chips", Description = "A large fillet of cod with our famous chunky fries!" });
  26. //stockList.Foods.Add(new FoodItem { Name = "Curry and chips", Description = "Spicy curry sauce finished with either our chunky or fine fries... both are great!" });
  27. //stockList.Foods.Add(new FoodItem { Name = "Freddie's fishcakes", Description = "Our fine blend fishcakes cooked fresh on the premises!" });
  28.  
  29. //stockList.Drinks.Add(new DrinkItem { Name = "Lemonade", Description = "Freshly squeezed lemonade" });
  30.  
  31. //open file
  32.  
  33.  
  34.  
  35. while (true)
  36. {
  37. PrintHelp();
  38.  
  39. Console.Write("> ");
  40. string input = Console.ReadLine();
  41.  
  42.  
  43. switch (input)
  44. {
  45. // to add a food item...
  46. case "1":
  47. stockList.AddFoodItem();
  48. break;
  49.  
  50. // add a drink item...
  51. case "2":
  52. stockList.AddDrinkItem();
  53. break;
  54.  
  55. // print a list of current items...
  56. case "3":
  57. Console.WriteLine("Foods: ");
  58. Console.WriteLine(String.Join(", ", stockList.GetFoodNames()));
  59.  
  60. Console.WriteLine("");
  61.  
  62. Console.WriteLine("Drinks: ");
  63. Console.WriteLine(String.Join(", ", stockList.GetDrinkNames()));
  64. break;
  65.  
  66. // edit exsisting records...
  67. case "4":
  68. Console.WriteLine("Would you like to edit food or drink?");
  69. var choice = Console.ReadLine();
  70.  
  71. Console.WriteLine("Please enter the ID of the item you wish to edit:");
  72. Console.WriteLine("");
  73. if (choice.ToLower() == "drink" || choice.ToLower() == "drinks")
  74. {
  75. Console.WriteLine("Drinks:");
  76. foreach (var drink in stockList.Drinks)
  77. {
  78. Console.WriteLine($"{stockList.Drinks.IndexOf(drink)}) {drink.Name}");
  79. }
  80.  
  81. // Get the ID of the item
  82. Console.WriteLine("");
  83. Console.Write("> ");
  84. var id = Convert.ToInt32(Console.ReadLine());
  85.  
  86. // Pull the item from the List
  87. var item = stockList.Drinks[id];
  88. stockList.Drinks.Remove(item); // Remove old item
  89.  
  90. // Add the new update item
  91. stockList.AddDrinkItem();
  92. }
  93. else if (choice.ToLower() == "food" || choice.ToLower() == "foods")
  94. {
  95. Console.WriteLine("Foods:");
  96. foreach (var food in stockList.Foods)
  97. {
  98. Console.WriteLine($"{stockList.Foods.IndexOf(food)}) {food.Name}");
  99. }
  100.  
  101. // Get the ID of the item
  102. Console.WriteLine("");
  103. Console.Write("> ");
  104. var id = Convert.ToInt32(Console.ReadLine());
  105.  
  106. // Pull the item from the List
  107. var item = stockList.Foods[id];
  108. stockList.Foods.Remove(item); // Remove old item
  109.  
  110. // Add the new update item
  111. stockList.AddFoodItem();
  112. }
  113.  
  114. break;
  115.  
  116. // output the total cost...
  117. case "5":
  118. Console.WriteLine("The total cost is: " + stockList.TotalCost());
  119. break;
  120.  
  121. // to quit selection...
  122. case "6":
  123. return;
  124. }
  125.  
  126. // Block so the user has time to read results
  127. Console.WriteLine(""); // Assign whitespace so dialogue is less cluttered
  128. Console.WriteLine("Press any key to continue.");
  129. Console.ReadKey(true);
  130.  
  131. Console.Clear();
  132. }
  133. }
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement