SaNik74

Passenger Train Configurator 2

Aug 8th, 2024
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Text.RegularExpressions;
  2.  
  3. namespace PassengerTrainConfigurator
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Train train = new Train();
  10.  
  11.             const string CreateTrainCommand = "1";
  12.             const string ExitCommand = "2";
  13.  
  14.             bool isWorking = true;
  15.             string userInput;
  16.  
  17.             while (isWorking)
  18.             {
  19.                 Console.ForegroundColor = ConsoleColor.Cyan;
  20.                 Console.WriteLine("Конфигуратор пасажирских поездов.\n");
  21.  
  22.                 Console.ResetColor();
  23.                 Console.WriteLine($"Чтобы создать новый поезд нажмите - {CreateTrainCommand}.\n" +
  24.                     $"Для выхода из программы нажмите {ExitCommand}.\n\n" +
  25.                     $"Ввод:");
  26.  
  27.                 userInput = Console.ReadLine();
  28.  
  29.                 switch (userInput)
  30.                 {
  31.                     case CreateTrainCommand:
  32.                         train.CreateTrain();
  33.                         break;
  34.  
  35.                     case ExitCommand:
  36.                         isWorking = false;
  37.                         break;
  38.  
  39.                     default:
  40.                         Console.WriteLine("Неизвестная комманда.");
  41.                         break;
  42.                 }
  43.  
  44.                 Console.ForegroundColor = ConsoleColor.DarkCyan;
  45.                 Console.WriteLine("\n\nДанные по каждому поезду:");
  46.                 Console.ResetColor();
  47.  
  48.                 train.ShowTrainInfo();
  49.  
  50.                 Console.ReadKey();
  51.                 Console.Clear();
  52.             }
  53.         }
  54.     }
  55.  
  56.     class Train
  57.     {
  58.         private List<int> _vans = new List<int>();
  59.         private List<Direction> _directions = new List<Direction>();
  60.         private List<int> _numberOfSellTickets = new List<int>();
  61.  
  62.         public void CreateTrain()
  63.         {
  64.             Van van = new Van();
  65.             Direction direction = new Direction();
  66.             Dispatcher dispatcher = new Dispatcher();
  67.  
  68.             int numberOfSellTickets = dispatcher.SellTickets();
  69.             int vansCount;
  70.  
  71.             vansCount = RoundUpDividing(numberOfSellTickets, van.CountSeats);
  72.  
  73.             _vans.Add(vansCount);
  74.             _directions.Add(direction.MakeDirection());
  75.             _numberOfSellTickets.Add(numberOfSellTickets);
  76.         }
  77.  
  78.         public void ShowTrainInfo()
  79.         {
  80.             for (int i = 0; i < _directions.Count; i++)
  81.             {
  82.                 Console.WriteLine($"Поезд отправляется из города {_directions[i].DepartyreCity} в город {_directions[i].ArrivalCity}.\n" +
  83.                     $"Билетов продано - {_numberOfSellTickets[i]}.\n" +
  84.                     $"Поезд состоит из {_vans[i]} вагонов.\n\n");
  85.             }
  86.  
  87.         }
  88.  
  89.         private int RoundUpDividing(int numerator, int denominator)
  90.         {
  91.             decimal numeratorInDec = Convert.ToDecimal(numerator);
  92.             decimal denominatorInDec = Convert.ToDecimal(denominator);
  93.             decimal resultInDec = Math.Ceiling(numeratorInDec / denominatorInDec);
  94.  
  95.             int result = Convert.ToInt32(resultInDec);
  96.  
  97.             return result;
  98.         }
  99.     }
  100.  
  101.     class DirectionFactory
  102.     {
  103.         protected List<string> Cities = new List<string>();
  104.  
  105.         public DirectionFactory()
  106.         {
  107.             Cities.Add("Москва");
  108.             Cities.Add("Санкт-Петербург");
  109.             Cities.Add("Тверь");
  110.             Cities.Add("Краснодар");
  111.             Cities.Add("Саратов");
  112.             Cities.Add("Нижний Новгород");
  113.             Cities.Add("Тверь");
  114.             Cities.Add("Ростов-на-Дону");
  115.             Cities.Add("Анапа");
  116.             Cities.Add("Сочи");
  117.             Cities.Add("Петрозаводск");
  118.         }
  119.     }
  120.  
  121.     class Direction : DirectionFactory
  122.     {
  123.         public Direction(string departyreCity = "", string arrivalCity = "")
  124.         {
  125.             DepartyreCity = departyreCity;
  126.             ArrivalCity = arrivalCity;
  127.         }
  128.  
  129.         public string DepartyreCity { get; private set; }
  130.         public string ArrivalCity { get; private set; }
  131.  
  132.         public Direction MakeDirection()
  133.         {
  134.             Random random = new Random();
  135.  
  136.             string departyreCity = Cities[random.Next(0, Cities.Count)];
  137.             string arrivalCity = Cities[random.Next(0, Cities.Count)];
  138.  
  139.             while (departyreCity == arrivalCity)
  140.             {
  141.                 arrivalCity = Cities[random.Next(0, Cities.Count)];
  142.             }
  143.  
  144.             Direction direction = new Direction(departyreCity, arrivalCity);
  145.  
  146.             return direction;
  147.         }
  148.     }
  149.  
  150.     class Van
  151.     {
  152.         public int CountSeats { get; private set; } = 36;
  153.     }
  154.  
  155.     class Dispatcher
  156.     {
  157.         public int SellTickets()
  158.         {
  159.             Random random = new Random();
  160.  
  161.             int minNumbersOfTickets = 1;
  162.             int maxNumbersOfTickets = 1800;
  163.             int numbersOfTickets = random.Next(minNumbersOfTickets, maxNumbersOfTickets);
  164.  
  165.             return numbersOfTickets;
  166.         }
  167.     }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment