Advertisement
desislava_topuzakova

CoffeeShop.cs

Jul 1st, 2023
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 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. //полета -> характеристики
  11. private string name;
  12. private List<Coffee> coffees;
  13.  
  14. public CoffeeShop()
  15. {
  16. //нов празен обект
  17. //name = null
  18. //coffees = null
  19. }
  20.  
  21. public CoffeeShop(string name)
  22. {
  23. //нов празен обект
  24. this.name = name;
  25. this.coffees = new List<Coffee>();
  26. }
  27.  
  28. public string Name
  29. {
  30. get
  31. {
  32. return name;
  33. }
  34. set
  35. {
  36. name = value;
  37. }
  38. }
  39.  
  40. public List<Coffee> Coffees
  41. {
  42. get
  43. {
  44. return coffees;
  45. }
  46. set
  47. {
  48. coffees = value;
  49. }
  50. }
  51.  
  52. public void AddCoffee(string name, double price)
  53. {
  54. Coffee coffee = new Coffee(name, price);
  55. coffees.Add(coffee);
  56. }
  57.  
  58. public double AveragePriceInRange(double start, double end)
  59. {
  60. //кафета с цени между start и end
  61. int count = 0;
  62. double sum = 0;
  63. foreach(Coffee coffee in coffees)
  64. {
  65. if (coffee.Price >= start && coffee.Price <= end)
  66. {
  67. count++;
  68. sum += coffee.Price;
  69. }
  70. }
  71.  
  72. //сумата от цената на кафетата
  73. //брой на кафетата
  74. return sum / count;
  75. }
  76.  
  77.  
  78. public List<string> RemoveCoffeesByPrice(double price)
  79. {
  80. List<String> leftCoofees = new List<string>(); // имената на кафетата с по-малка цена от дадената
  81. foreach (Coffee coffee in coffees)
  82. {
  83. if (coffee.Price < price)
  84. {
  85. leftCoofees.Add(coffee.Type);
  86. }
  87. }
  88. return leftCoofees;
  89. }
  90.  
  91. public List<Coffee> SortAscendingByType()
  92. {
  93. return coffees.OrderBy(coffee => coffee.Type).ToList();
  94. }
  95.  
  96. public List<Coffee> SortDescendingByPrice()
  97. {
  98. return coffees.OrderByDescending(coffee => coffee.Price).ToList();
  99. }
  100.  
  101. public bool CheckCoffeeIsInCoffeeShop(string type)
  102. {
  103. //true -> ако имаме такова кафе
  104. //false -> ако нямаме такова кафе
  105. foreach(Coffee coffee in coffees)
  106. {
  107. if (coffee.Type == type)
  108. {
  109. return true;
  110. }
  111. }
  112.  
  113. return false;
  114. }
  115.  
  116. public string[] ProvideInformationAboutAllCoffees()
  117. {
  118. List<string> infoList = new List<string>();
  119. foreach (Coffee coffee in coffees)
  120. {
  121. infoList.Add(coffee.ToString());
  122. }
  123.  
  124. return infoList.ToArray();
  125. }
  126.  
  127. }
  128. }
  129.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement