Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Net;
- using System.Linq;
- namespace TrainManager
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> destinationList = new List<string>();
- List<Train> trainList = new List<Train>();
- destinationList.Add("[1] Москва");
- destinationList.Add("[2] Владивосток");
- destinationList.Add("[3] Казань");
- destinationList.Add("[4] Уфа");
- destinationList.Add("[5] Калининград");
- destinationList.Add("[6] Новосибирск");
- while (true)
- {
- Console.SetCursorPosition(0, 10);
- Console.WriteLine("Здравствуйте!");
- Console.WriteLine("Выберите пункт A: ");
- int userInputA = PrintDestination(destinationList);
- Console.Clear();
- Console.SetCursorPosition(0, 10);
- Console.WriteLine("Выберите пункт B: ");
- int userInputB = PrintDestination(destinationList);
- Console.Clear();
- Console.SetCursorPosition(0, 10);
- Console.WriteLine("Нажмите Enter, чтобы продать билеты...");
- Console.ReadKey();
- int wagons = SellTickets();
- Console.WriteLine("Вагонов: " + wagons);
- Console.ReadKey();
- List<Wagon> wagonList = new List<Wagon>();
- Train.CreateWagons(wagons, wagonList);
- Train train1 = new Train(wagonList, destinationList[userInputA - 1], destinationList[userInputB - 1], "departured");
- trainList.Add(train1);
- Console.SetCursorPosition(0, 0);
- foreach (var item in trainList)
- {
- Console.WriteLine($"Поезд из {item.DestinationA} в {item.DestinationB}, вагонов - {item.showWagonAmount()}, Статус - {item.Status}");
- }
- }
- }
- static int PrintDestination(List<string> destinationList)
- {
- foreach (var item in destinationList)
- Console.WriteLine(item);
- int userInput = Convert.ToInt32(Console.ReadLine());
- return userInput;
- }
- static int SellTickets()
- {
- Random rng = new Random();
- int ticketSold = rng.Next(55, 500);
- Console.WriteLine("Билетов продано:" + ticketSold);
- int wagons = ticketSold / 54;
- if (ticketSold % 54 != 0)
- wagons += 1;
- return wagons;
- }
- }
- class Train
- {
- public string DestinationA { get; private set; }
- public string DestinationB { get; private set; }
- public string Status { get; private set; }
- private List<Wagon> _wagons = new List<Wagon>();
- public Train(List<Wagon> wagons, string destinationA, string destinationB, string status)
- {
- _wagons = wagons;
- DestinationA = destinationA;
- DestinationB = destinationB;
- Status = status;
- }
- public static void CreateWagons(int amount, List<Wagon> wagons)
- {
- for (int i = 0; i != amount; i++)
- {
- Wagon newWagon = new Wagon(54);
- wagons.Add(newWagon);
- }
- }
- public int showWagonAmount()
- {
- return _wagons.Count;
- }
- }
- class Wagon
- {
- public int Seats { get; private set; }
- public Wagon(int seats)
- {
- Seats = seats;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement