Advertisement
Rodunskiy

Untitled

Jul 26th, 2023
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         const string DirectionMoskowPetersburgCommand = "1";
  9.         const string DirectionMoskowSochiCommand = "2";
  10.         const string DirectionMoskowKazanCommand = "3";
  11.  
  12.         Train train = new Train();
  13.         Tickets tickets = new Tickets();
  14.  
  15.         string userInput;
  16.         bool isWorking = true;
  17.  
  18.         while(isWorking)
  19.         {
  20.             Console.WriteLine($"Выберите направление поезда:\n{DirectionMoskowPetersburgCommand})Москва - Питербург." +
  21.             $"\n{DirectionMoskowSochiCommand})Москва - Сочи.\n{DirectionMoskowKazanCommand})Москва - Казань.");
  22.  
  23.             userInput = Console.ReadLine();
  24.  
  25.             switch (userInput)
  26.             {
  27.                 case DirectionMoskowPetersburgCommand:
  28.                     int quantityTickets1 = tickets.QuantityTickets();
  29.                     train.CreatingTrain("Москва - Питербург", quantityTickets1);
  30.                     break;
  31.  
  32.                 case DirectionMoskowSochiCommand:
  33.                     int quantityTickets2 = tickets.QuantityTickets();
  34.                     train.CreatingTrain("Москва - Сочи", quantityTickets2);
  35.                     break;
  36.  
  37.                 case DirectionMoskowKazanCommand:
  38.                     int quantityTickets3 = tickets.QuantityTickets();
  39.                     train.CreatingTrain("Москва - Казань", quantityTickets3);
  40.                     break;
  41.             }
  42.         }
  43.     }
  44. }
  45.  
  46. class Van
  47. {
  48.     public Van(string name, int quantityPlaces)
  49.     {
  50.         Name = name;
  51.         QuantityPlaces = quantityPlaces;
  52.     }
  53.  
  54.     public string Name { get;private set; }
  55.     public int QuantityPlaces { get; private set; }
  56. }
  57.  
  58. class Depo
  59. {
  60.     List<Van> VanInDepot = new List<Van>() { new Van("SmallVan", 3), new Van("MiddleVan", 7), new Van("BigVan", 10) };
  61.  
  62.     public void ShowVan()
  63.     {
  64.         foreach (var van in VanInDepot)
  65.         {
  66.             Console.WriteLine($"Название вагона:{van.Name}\nКол-во мест:{van.QuantityPlaces}");
  67.         }
  68.     }
  69.  
  70.     public Van TransferVan()
  71.     {
  72.         Van van = null;
  73.         string userInput;
  74.  
  75.         Console.WriteLine($"Какие вагоны вы хотите добавить?");
  76.  
  77.         ShowVan();
  78.  
  79.         userInput = Console.ReadLine();
  80.  
  81.         if (VanInDepot.Count < 0)
  82.         {
  83.             Console.WriteLine("Вагонов больше нет.");
  84.             Console.ReadKey();
  85.         }
  86.         else
  87.         {
  88.             foreach (var item in VanInDepot)
  89.             {
  90.                 if (item.Name == userInput)
  91.                 {
  92.                     van = item;
  93.                 }
  94.             }
  95.         }
  96.  
  97.         VanInDepot.Remove(van);
  98.  
  99.         return van;
  100.     }
  101. }
  102.  
  103. class Train
  104. {
  105.     List<Van> vanOnTrain = new List<Van>();
  106.  
  107.     public void CreatingTrain(string text, int quantityTickets)
  108.     {
  109.         Depo depo = new Depo();
  110.         int quantityBusyPlace = 0;
  111.  
  112.         Console.WriteLine($"Количество купленных билетов на направление {text}: {quantityTickets}");
  113.  
  114.         while (quantityTickets > quantityBusyPlace)
  115.         {
  116.             Van van = depo.TransferVan();
  117.             quantityBusyPlace += van.QuantityPlaces;
  118.             vanOnTrain.Add(van);
  119.  
  120.             if (quantityTickets > quantityBusyPlace)
  121.             {
  122.                 Console.WriteLine("В поезде недостаточно мест для перевозки пассажиров! Добавьте еще вагонов.");
  123.             }
  124.             else
  125.             {
  126.                 Console.WriteLine("Поезд отправляется!");
  127.             }
  128.         }
  129.     }
  130. }
  131.  
  132. class Tickets
  133. {
  134.     public int QuantityTickets()
  135.     {
  136.         Random random = new Random();
  137.         int quantityTickets;
  138.         int maxTickets = 20;
  139.  
  140.         quantityTickets = random.Next(maxTickets);
  141.  
  142.         return quantityTickets;
  143.     }
  144. }
  145.  
  146.  
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement