Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main(string[] args)
- {
- const string DirectionMoskowPetersburgCommand = "1";
- const string DirectionMoskowSochiCommand = "2";
- const string DirectionMoskowKazanCommand = "3";
- Train train = new Train();
- Tickets tickets = new Tickets();
- string userInput;
- bool isWorking = true;
- while(isWorking)
- {
- Console.WriteLine($"Выберите направление поезда:\n{DirectionMoskowPetersburgCommand})Москва - Питербург." +
- $"\n{DirectionMoskowSochiCommand})Москва - Сочи.\n{DirectionMoskowKazanCommand})Москва - Казань.");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case DirectionMoskowPetersburgCommand:
- int quantityTickets1 = tickets.QuantityTickets();
- train.CreatingTrain("Москва - Питербург", quantityTickets1);
- break;
- case DirectionMoskowSochiCommand:
- int quantityTickets2 = tickets.QuantityTickets();
- train.CreatingTrain("Москва - Сочи", quantityTickets2);
- break;
- case DirectionMoskowKazanCommand:
- int quantityTickets3 = tickets.QuantityTickets();
- train.CreatingTrain("Москва - Казань", quantityTickets3);
- break;
- }
- }
- }
- }
- class Van
- {
- public Van(string name, int quantityPlaces)
- {
- Name = name;
- QuantityPlaces = quantityPlaces;
- }
- public string Name { get;private set; }
- public int QuantityPlaces { get; private set; }
- }
- class Depo
- {
- List<Van> VanInDepot = new List<Van>() { new Van("SmallVan", 3), new Van("MiddleVan", 7), new Van("BigVan", 10) };
- public void ShowVan()
- {
- foreach (var van in VanInDepot)
- {
- Console.WriteLine($"Название вагона:{van.Name}\nКол-во мест:{van.QuantityPlaces}");
- }
- }
- public Van TransferVan()
- {
- Van van = null;
- string userInput;
- Console.WriteLine($"Какие вагоны вы хотите добавить?");
- ShowVan();
- userInput = Console.ReadLine();
- if (VanInDepot.Count < 0)
- {
- Console.WriteLine("Вагонов больше нет.");
- Console.ReadKey();
- }
- else
- {
- foreach (var item in VanInDepot)
- {
- if (item.Name == userInput)
- {
- van = item;
- }
- }
- }
- VanInDepot.Remove(van);
- return van;
- }
- }
- class Train
- {
- List<Van> vanOnTrain = new List<Van>();
- public void CreatingTrain(string text, int quantityTickets)
- {
- Depo depo = new Depo();
- int quantityBusyPlace = 0;
- Console.WriteLine($"Количество купленных билетов на направление {text}: {quantityTickets}");
- while (quantityTickets > quantityBusyPlace)
- {
- Van van = depo.TransferVan();
- quantityBusyPlace += van.QuantityPlaces;
- vanOnTrain.Add(van);
- if (quantityTickets > quantityBusyPlace)
- {
- Console.WriteLine("В поезде недостаточно мест для перевозки пассажиров! Добавьте еще вагонов.");
- }
- else
- {
- Console.WriteLine("Поезд отправляется!");
- }
- }
- }
- }
- class Tickets
- {
- public int QuantityTickets()
- {
- Random random = new Random();
- int quantityTickets;
- int maxTickets = 20;
- quantityTickets = random.Next(maxTickets);
- return quantityTickets;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement