Advertisement
desislava_topuzakova

Untitled

Jul 2nd, 2023
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace RegularExam_UASD
  7. {
  8. internal class CoffeeShop
  9. {
  10. private string name;
  11. private List<Coffee> coffees;
  12.  
  13. public CoffeeShop()
  14. {
  15.  
  16. }
  17.  
  18. public CoffeeShop(string name)
  19. {
  20. Name = name;
  21. Coffees = new List<Coffee>();
  22. }
  23.  
  24. public string Name
  25. {
  26. get
  27. {
  28. return name;
  29. }
  30. set
  31. {
  32. name = value;
  33. }
  34. }
  35.  
  36. public List<Coffee> Coffees
  37. {
  38. get
  39. {
  40. return coffees;
  41. }
  42. set
  43. {
  44. coffees = value;
  45. }
  46. }
  47.  
  48. public void AddCoffee(string type, double price)
  49. {
  50. Coffee coffee = new Coffee(type, price);
  51. Coffees.Add(coffee);
  52. }
  53.  
  54. public double AveragePriceInRange(double start, double end)
  55. {
  56. double sum = 0;
  57. int count = 0;
  58. foreach (Coffee coffee in Coffees)
  59. {
  60. if (coffee.Price >= start && coffee.Price <= end)
  61. {
  62. sum += coffee.Price;
  63. count++;
  64. }
  65. }
  66.  
  67. return sum / count;
  68. }
  69.  
  70. public List<string> FilterCoffeesByPrice(double price)
  71. {
  72. List<String> leftCoffees = new List<String>();
  73. foreach (Coffee coffee in Coffees)
  74. {
  75. if (coffee.Price < price)
  76. {
  77. leftCoffees.Add(coffee.Type);
  78. }
  79. }
  80. return leftCoffees;
  81. }
  82.  
  83. public List<Coffee> SortAscendingByType()
  84. {
  85. List<Coffee> sorted = Coffees.OrderBy(coffee => coffee.Type).ToList();
  86. Coffees = sorted;
  87. return sorted;
  88. }
  89.  
  90. public List<Coffee> SortDescendingByPrice()
  91. {
  92. List<Coffee> sorted = Coffees.OrderByDescending(coffee => coffee.Price).ToList();
  93. Coffees = sorted;
  94. return sorted;
  95. }
  96.  
  97. public bool CheckCoffeeIsInCoffeeShop(string type)
  98. {
  99. foreach (Coffee coffee in Coffees)
  100. {
  101. if (coffee.Type == type)
  102. {
  103. return true;
  104. }
  105. }
  106.  
  107. return false;
  108. }
  109.  
  110. public string[] ProvideInformationAboutAllCoffees()
  111. {
  112. List<string> infoList = new List<string>();
  113. foreach (Coffee coffee in Coffees)
  114. {
  115. infoList.Add(coffee.ToString());
  116. }
  117. return infoList.ToArray();
  118. }
  119. }
  120. }
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement