Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal class Program
- {
- static void Main(string[] args)
- {
- const string CommandCreateRoute = "1";
- const string CommandSendTrain = "2";
- const string CommandExit = "3";
- RailwayStation railwayStation = new RailwayStation();
- TrainFormation trainFormation = new TrainFormation();
- List<string> allTrainRoutes = new List<string>();
- bool isWorking = true;
- while (isWorking)
- {
- Console.Clear();
- Console.WriteLine("== Список всех рейсов ==");
- railwayStation.GetInformationAboutAllRoutes(allTrainRoutes);
- Console.WriteLine();
- Console.WriteLine("===== Текущий рейс =====");
- Console.WriteLine(trainFormation.GetCurrentRouteInfo());
- Console.WriteLine("========================");
- Console.WriteLine();
- Console.WriteLine($"{CommandCreateRoute}. Создать направление" +
- $"\n{CommandSendTrain}. Отправить поезд" +
- $"\n{CommandExit}. Выход");
- Console.Write("Выберите действие: "); ;
- string userInput = Console.ReadLine();
- switch (userInput)
- {
- case CommandCreateRoute:
- trainFormation.TrainRouteFormation();
- break;
- case CommandSendTrain:
- trainFormation.SendTrain(allTrainRoutes);
- break;
- case CommandExit:
- isWorking = false;
- break;
- default:
- Console.WriteLine("Некорректный ввод");
- break;
- }
- }
- }
- }
- class TrainFormation
- {
- private string _currentRoute;
- private int _ticketsSold;
- private int _trainCapacity;
- private double _maxCountOfCars = 15;
- private double _countOfSeatsInCarriage = 54;
- private bool _istrainCreated;
- private bool _isTicketsSold;
- public void TrainRouteFormation()
- {
- CreateCurrentRoute();
- SellTickets();
- CreateTrain();
- }
- public string GetCurrentRouteInfo()
- {
- return $"Текущее направление: {_currentRoute}\nПродано билетов: {_ticketsSold}\nВместимость поезда: {_trainCapacity}\nПоезд создан: {_istrainCreated}";
- }
- public void SendTrain(List<string> allCurrentTrainRoutes)
- {
- if (_currentRoute == null)
- {
- return;
- }
- allCurrentTrainRoutes.Add($"Маршрут следует до станции {_currentRoute} | Количество посажиров {_trainCapacity} | Количество вагонов {_maxCountOfCars}");
- ResetCurrentRoute();
- Console.WriteLine("\nПоезд отправлен\nНажмите любую клавишу чтобы продолжить!");
- Console.ReadKey();
- }
- private void CreateCurrentRoute()
- {
- ResetCurrentRoute();
- Console.Write("Введите направление: ");
- _currentRoute = Console.ReadLine();
- Console.WriteLine("Новое направление создано\n");
- }
- private void SellTickets()
- {
- Console.Write("Введите количество проданных билетов: ");
- if (int.TryParse(Console.ReadLine(), out int ticketsSold))
- {
- _ticketsSold += ticketsSold;
- _isTicketsSold = true;
- }
- else
- {
- Console.WriteLine("Некорректное количество билетов\n");
- _isTicketsSold = false;
- return;
- }
- Console.WriteLine($"{ticketsSold} билетов продано\n");
- }
- private void CreateTrain()
- {
- _trainCapacity = _ticketsSold;
- if (!_isTicketsSold)
- {
- return;
- }
- else if (_countOfSeatsInCarriage * _maxCountOfCars < _trainCapacity)
- {
- _maxCountOfCars = Math.Ceiling(_trainCapacity / _countOfSeatsInCarriage);
- }
- _istrainCreated = true;
- }
- private void ResetCurrentRoute()
- {
- _currentRoute = null;
- _ticketsSold = 0;
- _trainCapacity = 0;
- _istrainCreated = false;
- _maxCountOfCars = 15;
- }
- }
- class RailwayStation : TrainFormation
- {
- public void GetInformationAboutAllRoutes(List<string> allTrainRoutes)
- {
- for (int i = 0; i < allTrainRoutes.Count; i++)
- {
- Console.Write(allTrainRoutes[i] + "\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement