Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main(string[] args)
- {
- Depo depo = new Depo();
- depo.Work();
- }
- }
- class Depo
- {
- private static Random _random = new Random();
- private List<Train> _trains;
- private int _numberTrain = 1000;
- public Depo()
- {
- _trains = new List<Train>();
- }
- public void Work()
- {
- string goCommand = "Go";
- string exitCommand = "Exit";
- bool isWorking = true;
- while (isWorking)
- {
- Console.WriteLine($"Введите {goCommand} чтобы начать программу или {exitCommand} для выхода.");
- string userInput = Console.ReadLine();
- if (userInput == "Exit")
- {
- isWorking = false;
- }
- else if(userInput == "Go")
- {
- ShowInfo();
- CreateNewTrain();
- }
- }
- }
- private int CreateNewTickets()
- {
- int minIndexRandom = 5;
- int maxIndexRandom = 16;
- return _random.Next(minIndexRandom, maxIndexRandom);
- }
- private Direction CreateNewDirection()
- {
- string source;
- string destination;
- Console.WriteLine("Создание нового направления.\nВведите пункт отправления и пункт отбытия.");
- source = Console.ReadLine();
- destination = Console.ReadLine();
- while (String.IsNullOrWhiteSpace(source) || String.IsNullOrWhiteSpace(destination) || source.ToLower() == destination.ToLower())
- {
- Console.WriteLine("Ошибка. Введены не коректные данные");
- }
- Console.WriteLine($"Направление {source}-{destination} создано.");
- return new Direction(source, destination);
- }
- private void CreateNewTrain()
- {
- Direction direction = CreateNewDirection();
- _trains.Add(new Train(_numberTrain, direction, CreateNewTickets()));
- _numberTrain++;
- }
- private void ShowInfo()
- {
- foreach (var train in _trains)
- {
- train.ShowStatsTrain();
- }
- }
- }
- class Train
- {
- private List<Van> _vans;
- private List<Van> _vansInTrain;
- private Direction _direction;
- public Train(int number, Direction direction, int numberTickets)
- {
- Number = number;
- _direction = direction;
- _vans = new List<Van>() { new SmallVan(), new MediumVan(),new LargeVan() };
- _vansInTrain = new List<Van>();
- AddVans(numberTickets);
- }
- public int Number { get; private set; }
- public void AddVans(int numberTickets)
- {
- Console.WriteLine($"Кол-во купленных билетов:{numberTickets}");
- string vanName;
- Console.WriteLine("Какой вагон вы хотите добавить?");
- foreach (Van van in _vans)
- {
- van.ShowStatsVan();
- }
- vanName = Console.ReadLine();
- foreach (Van van in _vans)
- {
- while (van.Name == vanName && numberTickets > 0)
- {
- _vansInTrain.Add(van);
- numberTickets -= van.NumberSeats;
- }
- }
- }
- public void ShowStatsTrain()
- {
- Console.WriteLine($"Направление {_direction.Source}-{_direction.Destination} |Номер поезда {Number}| Кол-во вагонов {_vansInTrain.Count}");
- }
- }
- class Van
- {
- public Van(string name, int numberSeats)
- {
- Name = name;
- NumberSeats = numberSeats;
- }
- public string Name { get; private set; }
- public int NumberSeats { get; private set; }
- public void ShowStatsVan()
- {
- Console.WriteLine($"{Name}|Кол-во мест:{NumberSeats}");
- }
- }
- class SmallVan : Van
- {
- public SmallVan() : base ("Small", 5) { }
- }
- class MediumVan : Van
- {
- public MediumVan() : base("Medium", 10) { }
- }
- class LargeVan : Van
- {
- public LargeVan() : base("Large", 15) { }
- }
- class Direction
- {
- public Direction(string source, string destination)
- {
- Source = source;
- Destination = destination;
- }
- public string Source { get; private set; }
- public string Destination { get; private set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement