Advertisement
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 ConsoleApp35
- {
- class Program
- {
- static void Main(string[] args)
- {
- string inputDirection = null;
- Random rand = new Random();
- int currentPassenger;
- int wagonCount;
- int wagonCapacity;
- int remainingPassenger;
- while (true)
- {
- if (inputDirection == null)
- {
- Console.SetCursorPosition(0, 0);
- Console.WriteLine("Движение поездов не осуществляется\n");
- }
- else if (inputDirection != null)
- {
- Console.SetCursorPosition(0, 0);
- Console.WriteLine($"Поезд двигается по нарвлению { inputDirection}\n");
- }
- Console.WriteLine("Введите направление поезда\n");
- inputDirection = Console.ReadLine();
- Console.Clear();
- currentPassenger = rand.Next(200, 301);
- remainingPassenger = currentPassenger;
- wagonCount = rand.Next(5, 11);
- Wagon[] wagons = new Wagon[wagonCount];
- for (int i = 0; i < wagons.Length; i++)
- {
- if (i != (wagons.Length - 1) && remainingPassenger > 0)
- {
- wagonCapacity = rand.Next(20, (currentPassenger/ wagonCount));
- wagons[i] = new Wagon(i + 1, wagonCapacity);
- remainingPassenger -= wagonCapacity;
- }
- else if (i == (wagons.Length - 1) && remainingPassenger > 0)
- {
- wagons[i] = new Wagon(i + 1, remainingPassenger);
- break;
- }
- else if (remainingPassenger < 0)
- {
- break;
- }
- }
- Train train1 = new Train(inputDirection, wagons, currentPassenger);
- train1.ShowInfo();
- }
- }
- }
- class Train
- {
- public string Direction;
- public Wagon[] Wagons;
- public int CurrentPassenger;
- public Train(string direction, Wagon[] wagons, int currentPassenger)
- {
- Direction = direction;
- Wagons = wagons;
- CurrentPassenger=currentPassenger;
- }
- public void ShowInfo()
- {
- Console.SetCursorPosition(0, 6);
- Console.WriteLine($"поезд из {Wagons.Length} вагонов перевозит {CurrentPassenger} пассажиров по направлению {Direction} отправлен\n");
- for (int i = 0; i < Wagons.Length; i++)
- {
- Wagons[i].ShowWagons();
- }
- }
- }
- class Wagon
- {
- public int WagonCount;
- public int WagonCapacity;
- public Wagon(int wagonCount, int wagonCapacity)
- {
- WagonCount = wagonCount;
- WagonCapacity = wagonCapacity;
- }
- public void ShowWagons()
- {
- Console.WriteLine($"Номер вагона - {WagonCount}, вместимость вагона - {WagonCapacity}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement