Advertisement
OwlyOwl

pozezdzdzd

Jul 14th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.02 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.CreateWagons(wagons, wagonList);
  41.                 Train train1 = new Train(wagonList, destinationList[userInputA - 1], destinationList[userInputB - 1], "departured");
  42.                 trainList.Add(train1);
  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.     }
  71.     class Train
  72.     {
  73.         public string DestinationA { get; private set; }
  74.         public string DestinationB { get; private set; }
  75.         public string Status { get; private set; }
  76.  
  77.         private List<Wagon> _wagons = new List<Wagon>();
  78.  
  79.         public Train(List<Wagon> wagons, string destinationA, string destinationB, string status)
  80.         {
  81.             _wagons = wagons;
  82.             DestinationA = destinationA;
  83.             DestinationB = destinationB;
  84.             Status = status;
  85.         }
  86.         public void AddTrain(List<Wagon> wagons, string destinationA, string destinationB, string status)
  87.         {
  88.             Train newTrain = new Train(wagons, destinationA, destinationB, status);
  89.         }
  90.  
  91.         public static void CreateWagons(int amount, List<Wagon> wagons)
  92.         {
  93.             for (int i = 0; i != amount; i++)
  94.             {
  95.                 Wagon newWagon = new Wagon(54);
  96.                 wagons.Add(newWagon);
  97.             }
  98.         }
  99.  
  100.         public int showWagonAmount()
  101.         {
  102.             return _wagons.Count;
  103.         }
  104.     }
  105.  
  106.     class Wagon
  107.     {
  108.         public int Seats { get; private set; }
  109.  
  110.         public Wagon(int seats)
  111.         {
  112.             Seats = seats;
  113.         }
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement