Advertisement
Rodunskiy

Untitled

Aug 3rd, 2023
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4.  
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Depo depo = new Depo();
  10.  
  11. while (true)
  12. {
  13. depo.Work();
  14. }
  15. }
  16. }
  17.  
  18. class Depo
  19. {
  20. private static Random random = new Random();
  21.  
  22. private List<Train> _trains;
  23.  
  24. private string _pointA;
  25. private string _pointB;
  26. private int _numberTickets;
  27.  
  28. public Depo()
  29. {
  30. _trains = new List<Train>();
  31. }
  32.  
  33. public void Work()
  34. {
  35. ShowInfo();
  36.  
  37. _numberTickets = AddNewTickets();
  38.  
  39. if (CreateNewDirection())
  40. {
  41. Console.WriteLine($"Кол-во купленных билетов:{_numberTickets}");
  42.  
  43. CreateNewTrain();
  44. }
  45. }
  46.  
  47. private int AddNewTickets()
  48. {
  49. int minIndexRandom = 5;
  50. int maxIndexRandom = 16;
  51.  
  52. int temporarynumberTickets = random.Next(minIndexRandom, maxIndexRandom);
  53.  
  54. return temporarynumberTickets;
  55. }
  56.  
  57. private bool CreateNewDirection()
  58. {
  59. string pointA;
  60. string pointB;
  61.  
  62. Console.WriteLine("Создание нового направления.\nВведите пункт отправления и пункт отбытия.");
  63. pointA = Console.ReadLine();
  64. pointB = Console.ReadLine();
  65.  
  66. if (pointA == null || pointB == null)
  67. {
  68. Console.WriteLine("Ошибка. Введены не коректные данные");
  69. return false;
  70. }
  71. else
  72. {
  73. _pointA = pointA;
  74. _pointB = pointB;
  75.  
  76. Console.WriteLine($"Направление {_pointA}-{_pointB} создано.");
  77.  
  78. return true;
  79. }
  80. }
  81.  
  82. private void CreateNewTrain()
  83. {
  84. int numberTrain = 1000;
  85.  
  86. _trains.Add(new Train(numberTrain, new Direction(_pointA, _pointB), _numberTickets));
  87.  
  88. numberTrain++;
  89. }
  90.  
  91. private void ShowInfo()
  92. {
  93. foreach (var train in _trains)
  94. {
  95. Console.WriteLine($"Направление {_pointA}-{_pointB} |Номер поезда {train.Number}| Кол-во вагонов {train.QuantityVans}");
  96. }
  97. }
  98. }
  99.  
  100. class Train
  101. {
  102. private List<Van> _vans;
  103. private List<Van> _vansInTrain;
  104. private Direction _direction;
  105.  
  106. public Train(int number, Direction direction, int numberTickets)
  107. {
  108. _direction = direction;
  109. _vans = new List<Van>() { new SmallVan(), new MediumVan(),new LargeVan() };
  110. _vansInTrain = new List<Van>();
  111.  
  112. QuantityVans = AddNewVans(numberTickets);
  113. }
  114.  
  115. public int Number { get; private set; }
  116. public int QuantityVans { get; private set; }
  117.  
  118. public int AddNewVans(int numberTickets)
  119. {
  120. string vanName;
  121. int quantityVans = 0;
  122.  
  123. Console.WriteLine("Какой вагон вы хотите добавить?");
  124.  
  125. foreach (Van van in _vans)
  126. {
  127. van.ShowStats();
  128. }
  129.  
  130. vanName = Console.ReadLine();
  131.  
  132. foreach (Van van in _vans)
  133. {
  134. while (van.Name == vanName && numberTickets > 0)
  135. {
  136. _vansInTrain.Add(van);
  137. numberTickets -= van.NumberSeats;
  138. quantityVans++;
  139. }
  140.  
  141. break;
  142. }
  143.  
  144. return quantityVans;
  145. }
  146. }
  147.  
  148. class Van
  149. {
  150. public Van(string name, int numberSeats)
  151. {
  152. Name = name;
  153. NumberSeats = numberSeats;
  154. }
  155.  
  156. public string Name { get; private set; }
  157. public int NumberSeats { get; private set; }
  158.  
  159. public void ShowStats()
  160. {
  161. Console.WriteLine($"{Name}|Кол-во мест:{NumberSeats}");
  162. }
  163. }
  164.  
  165. class SmallVan : Van
  166. {
  167. public SmallVan() : base ("Small", 5) { }
  168.  
  169. }
  170.  
  171. class MediumVan : Van
  172. {
  173. public MediumVan() : base("Medium", 10) { }
  174. }
  175.  
  176. class LargeVan : Van
  177. {
  178. public LargeVan() : base("Large", 15) { }
  179. }
  180.  
  181. class Direction
  182. {
  183. public Direction(string pointA, string pointB)
  184. {
  185. PointA = pointA;
  186. PointB = pointB;
  187. }
  188.  
  189. public string PointA { get; private set; }
  190. public string PointB { get; private set; }
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement