Advertisement
OwlyOwl

poezd

Jul 12th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.92 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.                 Wagon.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.Wagons.Count}, Статус - {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.         public 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.  
  92.     class Wagon
  93.     {
  94.         public int Seats { get; private set; }
  95.  
  96.         public Wagon(int seats)
  97.         {
  98.             Seats = seats;
  99.         }
  100.  
  101.         public static void createWagons(int amount, List<Wagon> wagons)
  102.         {
  103.             for (int i = 0; i != amount; i++)
  104.             {
  105.                 Wagon newWagon = new Wagon(54);
  106.                 wagons.Add(newWagon);
  107.             }
  108.         }
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement