Advertisement
Guest User

Zver

a guest
Feb 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.61 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Text;
  4. using System.Collections.Generic;
  5.  
  6. namespace TouristAgency
  7. {
  8. class Client
  9. {
  10. private string name;
  11. private string surename;
  12. private int age;
  13. private string destination;
  14. private int frontDeskNumber;
  15.  
  16. public string Name { get { return name; } set { name = value; } }
  17. public string Surename { get { return surename; } set { surename = value; } }
  18. public int Age { get { return age; } set { age = value; } }
  19. public string Destination { get { return destination; } set { destination = value; } }
  20. public int FrontDeskNumber { get { return frontDeskNumber; } set { frontDeskNumber = value; } }
  21.  
  22. public Client(string name, string surename, int age, string destination, int frontDeskNumber)
  23. {
  24. this.name = name;
  25. this.surename = surename;
  26. this.age = age;
  27. this.destination = destination;
  28. this.frontDeskNumber = frontDeskNumber;
  29. }
  30.  
  31. public int getPrice()
  32. {
  33. return destination.Length * 2000;
  34. }
  35. }
  36.  
  37. class FrontDesk
  38. {
  39. private int number;
  40. public List<Client> deskClients;
  41.  
  42. public int Number { get { return number; } set { number = value; } }
  43.  
  44. public FrontDesk(int number)
  45. {
  46. this.number = number;
  47. deskClients = new List<Client>();
  48. }
  49.  
  50. public void addClient(Client client)
  51. {
  52. deskClients.Add(client);
  53. }
  54.  
  55. public int GetClientLength()
  56. {
  57. return deskClients.Count;
  58. }
  59.  
  60. public int calculatePrice()
  61. {
  62. int suma = 0;
  63. foreach (Client c in deskClients)
  64. {
  65. suma += c.getPrice();
  66. }
  67. return suma;
  68. }
  69.  
  70. public string toString()
  71. {
  72. StringBuilder sb = new StringBuilder();
  73. sb.Append("Salter ").Append(number+" :").Append("\n");
  74. sb.Append(GetClientLength()).Append(" karti").Append("\n");
  75. return sb.ToString();
  76. }
  77. }
  78.  
  79. class TouristAgency
  80. {
  81. private string name;
  82. private int numberOfDesks;
  83. List<Client> clients;
  84. List<FrontDesk> frontDesks;
  85. List<String> destinations;
  86.  
  87. public TouristAgency(string name, int numberOfDesks)
  88. {
  89. this.name = name;
  90. this.numberOfDesks = numberOfDesks;
  91. clients = new List<Client>();
  92. frontDesks = new List<FrontDesk>(numberOfDesks);
  93. destinations = new List<string>();
  94. createDestinations();
  95. }
  96.  
  97. public void createDestinations()
  98. {
  99. destinations.Add("Rim");
  100. destinations.Add("London");
  101. destinations.Add("Tokio");
  102. destinations.Add("Sofija");
  103. destinations.Add("Istanbul");
  104. destinations.Add("Toronto");
  105. destinations.Add("Majami");
  106. destinations.Add("Zagreb");
  107. destinations.Add("Belgrad");
  108. destinations.Add("Moskva");
  109. }
  110.  
  111. public void ClientService(Client client)
  112. {
  113. clients.Add(client);
  114. if (destinations.Contains(client.Destination))
  115. {
  116. if (CheckForDesks(client) == true)
  117. {
  118. FrontDesk fd = CheckIfDeskExists(client.FrontDeskNumber);
  119. if (fd == null)
  120. {
  121. fd = new FrontDesk(client.FrontDeskNumber);
  122. fd.addClient(client);
  123. frontDesks.Add(fd);
  124. }
  125. else
  126. {
  127. fd.addClient(client);
  128. }
  129. }
  130.  
  131. }
  132. }
  133.  
  134. public void GetNumberOfClients(int frontDeskNumber)
  135. {
  136. FrontDesk fd = CheckIfDeskExists(frontDeskNumber);
  137. if(fd!=null)
  138. Console.Write(fd.GetClientLength());
  139. }
  140.  
  141. public void GetPriceFromDesk(int frontDeskNumber)
  142. {
  143. FrontDesk fd = CheckIfDeskExists(frontDeskNumber);
  144. if (fd != null)
  145. Console.Write(fd.calculatePrice());
  146. }
  147.  
  148. public string toString()
  149. {
  150. StringBuilder sb = new StringBuilder();
  151. foreach (FrontDesk fd in frontDesks)
  152. {
  153. sb.Append(fd.toString()).Append("\n");
  154. }
  155. return sb.ToString();
  156. }
  157.  
  158. public bool CheckForDesks(Client client)
  159. {
  160. if (client.FrontDeskNumber < 0 || client.FrontDeskNumber >= numberOfDesks)
  161. return false;
  162. return true;
  163. }
  164.  
  165. public int CalculatePrice()
  166. {
  167. int sum = 0;
  168. foreach(FrontDesk fd in frontDesks)
  169. {
  170. sum += fd.calculatePrice();
  171. }
  172. return sum;
  173. }
  174.  
  175. public FrontDesk CheckIfDeskExists(int FrontDeskNumber)
  176. {
  177. foreach (FrontDesk fd in frontDesks)
  178. {
  179. if (fd.Number ==FrontDeskNumber)
  180. return fd;
  181. }
  182. return null;
  183. }
  184.  
  185. public double success()
  186. {
  187. int numDeskClients = 0;
  188.  
  189. foreach(FrontDesk fd in frontDesks)
  190. {
  191. numDeskClients += fd.GetClientLength();
  192. }
  193. return (double)(numDeskClients / clients.Count);
  194. }
  195.  
  196. }
  197.  
  198. class Program
  199. {
  200. public static void Start(TouristAgency touristAgency)
  201. {
  202. while (true)
  203. {
  204. int n = int.Parse(Console.ReadLine());
  205.  
  206. switch (n)
  207. {
  208. case 1:
  209. Client client = ClientParser();
  210. touristAgency.ClientService(client);
  211. break;
  212. case 2:
  213. int frontDeskNumber = int.Parse(Console.ReadLine());
  214. touristAgency.GetNumberOfClients(frontDeskNumber);
  215. break;
  216. case 3:
  217. int frontDeskNumber1 = int.Parse(Console.ReadLine());
  218. touristAgency.GetPriceFromDesk(frontDeskNumber1);
  219. break;
  220. case 4:
  221. Console.Write(touristAgency.toString());
  222. break;
  223. case 5:
  224. Console.Write(touristAgency.CalculatePrice());
  225. break;
  226. case 6:
  227. Console.Write(touristAgency.success());
  228. break;
  229. case 7:
  230. return;
  231. }
  232. }
  233. }
  234.  
  235. public static Client ClientParser()
  236. {
  237. string name = Console.ReadLine();
  238. string surename = Console.ReadLine();
  239. int age = int.Parse(Console.ReadLine());
  240. string destination = Console.ReadLine();
  241. int frontDeskNumber = int.Parse(Console.ReadLine());
  242. Client client = new Client(name, surename, age, destination, frontDeskNumber);
  243. return client;
  244. }
  245.  
  246. static void Main(string[] args)
  247. {
  248. TouristAgency touristAgency = new TouristAgency("World", 5);
  249. Start(touristAgency);
  250. }
  251. }
  252.  
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement