Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string userInput;
- bool isWorking = true;
- Database database = new Database();
- while (isWorking)
- {
- Console.ReadKey();
- Console.Clear();
- database.ShowInfo();
- Console.WriteLine("\n\n\nМеню:\n1.Составить план поезда\n2.Выйти");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "1":
- Console.WriteLine("Пункт отправки: ");
- string firstdirection = Console.ReadLine();
- Console.WriteLine("Пункт прибытия: ");
- string secondDirection = Console.ReadLine();
- database.AddTrainPlane(firstdirection, secondDirection);
- Console.WriteLine("Поезд отправлен");
- break;
- case "2":
- isWorking = false;
- break;
- default:
- Console.WriteLine("Нет такой команды");
- break;
- }
- }
- }
- class Direction
- {
- private string _firstDirection;
- private string _secondDirection;
- public Direction(string firstDirection, string secondDirection)
- {
- _firstDirection = firstDirection;
- _secondDirection = secondDirection;
- }
- public void ShowInfo()
- {
- Console.Write($"{_firstDirection} - {_secondDirection} || ");
- }
- }
- class Train
- {
- private Random _random;
- private int _railwayCarriage;
- private int _countPlace;
- private int _countPassengers;
- public Train()
- {
- _random = new Random();
- _countPassengers = _random.Next(10, 101);
- _countPlace = _random.Next(5, 16);
- float needRailwayCarriage = Convert.ToSingle(_countPassengers) / Convert.ToSingle(_countPlace);
- _railwayCarriage = Convert.ToInt32(Math.Ceiling(needRailwayCarriage));
- }
- public void Showinfo()
- {
- Console.Write($"Пассажиров: {_countPassengers} || Мест в вагоне: {_countPlace} || Вагонов: {_railwayCarriage}\n");
- }
- }
- class Database
- {
- private List<Direction> _direction;
- private List<Train> _train;
- public Database()
- {
- _direction = new List<Direction>();
- _train = new List<Train>();
- }
- public void AddTrainPlane(string firstDirection, string secondDirection)
- {
- _direction.Add(new Direction(firstDirection, secondDirection));
- _train.Add(new Train());
- }
- public void ShowInfo()
- {
- if (_direction.Count == 0)
- {
- Console.WriteLine("Нет активных рейсов!");
- }
- else
- {
- Console.WriteLine("Рейсы: ");
- for (int i = 0; i < _direction.Count; i++)
- {
- _direction[i].ShowInfo();
- _train[i].Showinfo();
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment