Anonim_999

TrainPlane

Jul 25th, 2021 (edited)
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string userInput;
  10.             bool isWorking = true;
  11.             Database database = new Database();
  12.  
  13.             while (isWorking)
  14.             {
  15.                 Console.ReadKey();
  16.                 Console.Clear();
  17.                 database.ShowInfo();
  18.                 Console.WriteLine("\n\n\nМеню:\n1.Составить план поезда\n2.Выйти");
  19.                 userInput = Console.ReadLine();
  20.  
  21.                 switch (userInput)
  22.                 {
  23.                     case "1":
  24.                         Console.WriteLine("Пункт отправки: ");
  25.                         string firstdirection = Console.ReadLine();
  26.                         Console.WriteLine("Пункт прибытия: ");
  27.                         string secondDirection = Console.ReadLine();
  28.                         database.AddTrainPlane(firstdirection, secondDirection);
  29.                         Console.WriteLine("Поезд отправлен");
  30.                         break;
  31.                     case "2":
  32.                         isWorking = false;
  33.                         break;
  34.                     default:
  35.                         Console.WriteLine("Нет такой команды");
  36.                         break;
  37.                 }
  38.             }
  39.         }
  40.  
  41.         class Direction
  42.         {
  43.             private string _firstDirection;
  44.             private string _secondDirection;
  45.  
  46.             public Direction(string firstDirection, string secondDirection)
  47.             {
  48.                 _firstDirection = firstDirection;
  49.                 _secondDirection = secondDirection;
  50.             }
  51.  
  52.             public void ShowInfo()
  53.             {
  54.                 Console.Write($"{_firstDirection} - {_secondDirection} || ");
  55.             }
  56.         }
  57.  
  58.         class Train
  59.         {
  60.             private Random _random;
  61.             private int _railwayCarriage;
  62.             private int _countPlace;
  63.             private int _countPassengers;
  64.  
  65.             public Train()
  66.             {
  67.                 _random = new Random();
  68.                 _countPassengers = _random.Next(10, 101);
  69.                 _countPlace = _random.Next(5, 16);
  70.                 float needRailwayCarriage = Convert.ToSingle(_countPassengers) / Convert.ToSingle(_countPlace);
  71.                 _railwayCarriage = Convert.ToInt32(Math.Ceiling(needRailwayCarriage));
  72.             }
  73.  
  74.             public void Showinfo()
  75.             {
  76.                 Console.Write($"Пассажиров: {_countPassengers} || Мест в вагоне: {_countPlace} || Вагонов: {_railwayCarriage}\n");
  77.             }
  78.         }
  79.  
  80.         class Database
  81.         {
  82.             private List<Direction> _direction;
  83.             private List<Train> _train;
  84.  
  85.             public Database()
  86.             {
  87.                 _direction = new List<Direction>();
  88.                 _train = new List<Train>();
  89.             }
  90.  
  91.             public void AddTrainPlane(string firstDirection, string secondDirection)
  92.             {
  93.                 _direction.Add(new Direction(firstDirection, secondDirection));
  94.                 _train.Add(new Train());
  95.             }
  96.  
  97.             public void ShowInfo()
  98.             {
  99.                 if (_direction.Count == 0)
  100.                 {
  101.                     Console.WriteLine("Нет активных рейсов!");
  102.                 }
  103.                 else
  104.                 {
  105.                     Console.WriteLine("Рейсы: ");
  106.                     for (int i = 0; i < _direction.Count; i++)
  107.                     {
  108.                         _direction[i].ShowInfo();
  109.                         _train[i].Showinfo();
  110.                     }
  111.                 }
  112.             }
  113.         }
  114.     }
  115. }
Add Comment
Please, Sign In to add comment