Advertisement
OwlyOwl

poezdix

Jul 14th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Net;
  4. using System.Linq;
  5.  
  6. namespace TrainManager
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<string> destinationList = new List<string>();
  13.             List<Train> trainList = new List<Train>();
  14.  
  15.             destinationList.Add("[1] Москва");
  16.             destinationList.Add("[2] Владивосток");
  17.             destinationList.Add("[3] Казань");
  18.             destinationList.Add("[4] Уфа");
  19.             destinationList.Add("[5] Калининград");
  20.             destinationList.Add("[6] Новосибирск");
  21.             while (true)
  22.             {
  23.  
  24.                 Console.SetCursorPosition(0, 10);
  25.                 Console.WriteLine("Здравствуйте!");
  26.                 Console.WriteLine("Выберите пункт A:  ");
  27.                 int userInputA = PrintDestination(destinationList);
  28.                 Console.Clear();
  29.                 Console.SetCursorPosition(0, 10);
  30.                 Console.WriteLine("Выберите пункт B:  ");
  31.                 int userInputB = PrintDestination(destinationList);
  32.                 Console.Clear();
  33.                 Console.SetCursorPosition(0, 10);
  34.                 Console.WriteLine("Нажмите Enter, чтобы продать билеты...");
  35.                 Console.ReadKey();
  36.                 int wagons = SellTickets();
  37.                 Console.WriteLine("Вагонов: " + wagons);
  38.                 Console.ReadKey();
  39.                 List<Wagon> wagonList = new List<Wagon>();
  40.                 Train newTrain = new Train(destinationList[userInputA - 1], destinationList[userInputB - 1], "departured");
  41.                 newTrain.CreateWagons(wagons);
  42.                 trainList.Add(newTrain);
  43.                 Console.SetCursorPosition(0, 0);
  44.                 foreach (var item in trainList)
  45.                 {
  46.                     Console.WriteLine($"Поезд из {item.DestinationA} в {item.DestinationB}, вагонов - {item.showWagonAmount()}, Статус - {item.Status}");
  47.                 }
  48.             }
  49.         }
  50.  
  51.         static int PrintDestination(List<string> destinationList)
  52.         {
  53.             foreach (var item in destinationList)
  54.                 Console.WriteLine(item);
  55.             int userInput = Convert.ToInt32(Console.ReadLine());
  56.             return userInput;
  57.         }
  58.  
  59.         static int SellTickets()
  60.         {
  61.             Random rng = new Random();
  62.             int ticketSold = rng.Next(55, 500);
  63.             Console.WriteLine("Билетов продано:" + ticketSold);
  64.             int wagons = ticketSold / 54;
  65.             if (ticketSold % 54 != 0)
  66.                 wagons += 1;
  67.             return wagons;
  68.         }
  69.     }
  70.     class Train
  71.     {
  72.         public string DestinationA { get; private set; }
  73.         public string DestinationB { get; private set; }
  74.         public string Status { get; private set; }
  75.  
  76.         private List<Wagon> _wagons = new List<Wagon>();
  77.  
  78.         public Train(string destinationA, string destinationB, string status)
  79.         {
  80.             List<Wagon> _wagons = new List<Wagon>();
  81.             DestinationA = destinationA;
  82.             DestinationB = destinationB;
  83.             Status = status;
  84.         }
  85.  
  86.         public void CreateWagons(int amount)
  87.         {
  88.             for (int i = 0; i != amount; i++)
  89.             {
  90.                 Wagon newWagon = new Wagon(54);
  91.                 _wagons.Add(newWagon);
  92.             }
  93.         }
  94.  
  95.         public int showWagonAmount()
  96.         {
  97.             return _wagons.Count;
  98.         }
  99.     }
  100.  
  101.     class Wagon
  102.     {
  103.         public int Seats { get; private set; }
  104.  
  105.         public Wagon(int seats)
  106.         {
  107.             Seats = seats;
  108.         }
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement