Advertisement
OwlyOwl

TrainStation

Jul 5th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.24 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.  
  39.                 Train train1 = new Train(wagons, destinationList[userInputA - 1], destinationList[userInputB - 1], "departured");
  40.                 trainList.Add(train1);
  41.  
  42.                 Console.SetCursorPosition(0, 0);
  43.                 foreach (var item in trainList)
  44.                 {
  45.                     Console.WriteLine($"Поезд из {item.DestinationA} в {item.DestinationB}, вагонов - {item.Wagons}, Статус - {item.Status}");
  46.                 }
  47.             }
  48.         }
  49.  
  50.         static int printDestination(List<string> destinationList)
  51.         {
  52.             foreach (var item in destinationList)
  53.                 Console.WriteLine(item);
  54.             int userInput = Convert.ToInt32(Console.ReadLine());
  55.             return userInput;
  56.         }
  57.  
  58.         static int sellTickets()
  59.         {
  60.             Random rng = new Random();
  61.             int ticketSold = rng.Next(55, 500);
  62.             Console.WriteLine("Билетов продано:" + ticketSold);
  63.             int wagons = ticketSold / 54;
  64.             if (ticketSold % 54 != 0)
  65.                 wagons += 1;
  66.             return wagons;
  67.         }
  68.  
  69.     }
  70.     class Train
  71.     {
  72.         public int Wagons;
  73.         public string DestinationA;
  74.         public string DestinationB;
  75.         public string Status;
  76.  
  77.         public Train(int wagons, string destinationA, string destinationB, string status)
  78.         {
  79.             Wagons = wagons;
  80.             DestinationA = destinationA;
  81.             DestinationB = destinationB;
  82.             Status = status;
  83.         }
  84.         public void AddTrain(int wagons, string destinationA, string destinationB, string status)
  85.         {
  86.             Train newTrain = new Train(wagons, destinationA, destinationB, status);
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement