Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TrainPlanner
- {
- class Program
- {
- static void Main(string[] args)
- {
- TrainPlan Planner = new TrainPlan();
- Train ActiveTrain = new Train();
- bool RunProgram = true;
- while (RunProgram)
- {
- Console.Clear();
- ActiveTrain.ShowInfo();
- Console.WriteLine("1 - Задать новый рейс\n2 - Выход");
- int userInput = Convert.ToInt32(Console.ReadLine());
- switch (userInput)
- {
- case 1:
- Planner.CreateRoute();
- Planner.SellTickets();
- Planner.FormTrain();
- ActiveTrain = Planner.RunTrain();
- break;
- case 2:
- RunProgram = false;
- break;
- }
- }
- }
- class Car
- {
- public int Capacity;
- public Car(int carCapacity)
- {
- Capacity = carCapacity;
- }
- }
- class Train
- {
- public string Route;
- public Car[] Cars;
- public bool IsEnRoute;
- public int Capacity { get; private set; }
- public int OccupiedPlaces;
- public Train()
- {
- Cars = new Car[] { };
- }
- public void InsertCar(Car car)
- {
- Capacity += car.Capacity;
- Array.Resize(ref Cars, Cars.Length + 1);
- }
- public void ShowInfo()
- {
- if (IsEnRoute)
- {
- Console.WriteLine($"Поезд <{Route}> - всего мест:{Capacity} - из них занято: {OccupiedPlaces}");
- }
- else
- {
- Console.WriteLine("Состав не сформирован");
- }
- }
- }
- class TrainPlan
- {
- private Train _processedTrain;
- public int SoldTickets;
- public TrainPlan()
- {
- _processedTrain = new Train();
- }
- public void CreateRoute()
- {
- Console.WriteLine("Введите маршрут");
- _processedTrain.Route = Console.ReadLine();
- }
- public void SellTickets()
- {
- Random rand = new Random();
- SoldTickets = rand.Next(10, 1000);
- }
- public void FormTrain()
- {
- Random rand = new Random();
- int carCapacity;
- while (_processedTrain.Capacity < SoldTickets)
- {
- carCapacity = rand.Next(30, 50);
- _processedTrain.InsertCar(new Car(carCapacity));
- }
- _processedTrain.OccupiedPlaces = SoldTickets;
- Console.WriteLine("Общая вместимость поезда: " + _processedTrain.Capacity);
- }
- public Train RunTrain()
- {
- _processedTrain.IsEnRoute = true;
- return _processedTrain;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment