Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Text.RegularExpressions;
- namespace PassengerTrainConfigurator
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Train train = new Train();
- const string CreateTrainCommand = "1";
- const string ExitCommand = "2";
- bool isWorking = true;
- string userInput;
- while (isWorking)
- {
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine("Конфигуратор пасажирских поездов.\n");
- Console.ResetColor();
- Console.WriteLine($"Чтобы создать новый поезд нажмите - {CreateTrainCommand}.\n" +
- $"Для выхода из программы нажмите {ExitCommand}.\n\n" +
- $"Ввод:");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case CreateTrainCommand:
- train.CreateTrain();
- break;
- case ExitCommand:
- isWorking = false;
- break;
- default:
- Console.WriteLine("Неизвестная комманда.");
- break;
- }
- Console.ForegroundColor = ConsoleColor.DarkCyan;
- Console.WriteLine("\n\nДанные по каждому поезду:");
- Console.ResetColor();
- train.ShowTrainInfo();
- Console.ReadKey();
- Console.Clear();
- }
- }
- }
- class Train
- {
- private List<int> _vans = new List<int>();
- private List<Direction> _directions = new List<Direction>();
- private List<int> _numberOfSellTickets = new List<int>();
- public void CreateTrain()
- {
- Van van = new Van();
- Direction direction = new Direction();
- Dispatcher dispatcher = new Dispatcher();
- int numberOfSellTickets = dispatcher.SellTickets();
- int vansCount;
- vansCount = RoundUpDividing(numberOfSellTickets, van.CountSeats);
- _vans.Add(vansCount);
- _directions.Add(direction.MakeDirection());
- _numberOfSellTickets.Add(numberOfSellTickets);
- }
- public void ShowTrainInfo()
- {
- for (int i = 0; i < _directions.Count; i++)
- {
- Console.WriteLine($"Поезд отправляется из города {_directions[i].DepartyreCity} в город {_directions[i].ArrivalCity}.\n" +
- $"Билетов продано - {_numberOfSellTickets[i]}.\n" +
- $"Поезд состоит из {_vans[i]} вагонов.\n\n");
- }
- }
- private int RoundUpDividing(int numerator, int denominator)
- {
- decimal numeratorInDec = Convert.ToDecimal(numerator);
- decimal denominatorInDec = Convert.ToDecimal(denominator);
- decimal resultInDec = Math.Ceiling(numeratorInDec / denominatorInDec);
- int result = Convert.ToInt32(resultInDec);
- return result;
- }
- }
- class DirectionFactory
- {
- protected List<string> Cities = new List<string>();
- public DirectionFactory()
- {
- Cities.Add("Москва");
- Cities.Add("Санкт-Петербург");
- Cities.Add("Тверь");
- Cities.Add("Краснодар");
- Cities.Add("Саратов");
- Cities.Add("Нижний Новгород");
- Cities.Add("Тверь");
- Cities.Add("Ростов-на-Дону");
- Cities.Add("Анапа");
- Cities.Add("Сочи");
- Cities.Add("Петрозаводск");
- }
- }
- class Direction : DirectionFactory
- {
- public Direction(string departyreCity = "", string arrivalCity = "")
- {
- DepartyreCity = departyreCity;
- ArrivalCity = arrivalCity;
- }
- public string DepartyreCity { get; private set; }
- public string ArrivalCity { get; private set; }
- public Direction MakeDirection()
- {
- Random random = new Random();
- string departyreCity = Cities[random.Next(0, Cities.Count)];
- string arrivalCity = Cities[random.Next(0, Cities.Count)];
- while (departyreCity == arrivalCity)
- {
- arrivalCity = Cities[random.Next(0, Cities.Count)];
- }
- Direction direction = new Direction(departyreCity, arrivalCity);
- return direction;
- }
- }
- class Van
- {
- public int CountSeats { get; private set; } = 36;
- }
- class Dispatcher
- {
- public int SellTickets()
- {
- Random random = new Random();
- int minNumbersOfTickets = 1;
- int maxNumbersOfTickets = 1800;
- int numbersOfTickets = random.Next(minNumbersOfTickets, maxNumbersOfTickets);
- return numbersOfTickets;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment