Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ConsoleApp35
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string inputDirection = null;
  13.             Random rand = new Random();
  14.             int currentPassenger;
  15.             int wagonCount;
  16.             int wagonCapacity;
  17.             int remainingPassenger;
  18.             while (true)
  19.             {
  20.                 if (inputDirection == null)
  21.                 {
  22.                     Console.SetCursorPosition(0, 0);
  23.                     Console.WriteLine("Движение поездов не осуществляется\n");
  24.                 }
  25.                 else if (inputDirection != null)
  26.                 {
  27.                     Console.SetCursorPosition(0, 0);
  28.                     Console.WriteLine($"Поезд двигается по нарвлению { inputDirection}\n");
  29.                 }
  30.                 Console.WriteLine("Введите направление поезда\n");
  31.                 inputDirection = Console.ReadLine();
  32.                 Console.Clear();
  33.                 currentPassenger = rand.Next(200, 301);
  34.                 remainingPassenger = currentPassenger;
  35.                 wagonCount = rand.Next(5, 11);
  36.                 Wagon[] wagons = new Wagon[wagonCount];
  37.                 for (int i = 0; i < wagons.Length; i++)
  38.                 {
  39.                     if (i != (wagons.Length - 1) && remainingPassenger > 0)
  40.                     {
  41.                         wagonCapacity = rand.Next(20, (currentPassenger/ wagonCount));
  42.                         wagons[i] = new Wagon(i + 1, wagonCapacity);
  43.                         remainingPassenger -= wagonCapacity;
  44.                     }
  45.                     else if (i == (wagons.Length - 1) && remainingPassenger > 0)
  46.                     {
  47.                         wagons[i] = new Wagon(i + 1, remainingPassenger);
  48.                         break;
  49.                     }
  50.                     else if (remainingPassenger < 0)
  51.                     {
  52.                         break;
  53.                     }
  54.                 }
  55.                 Train train1 = new Train(inputDirection, wagons, currentPassenger);
  56.                 train1.ShowInfo();
  57.             }
  58.         }
  59.     }
  60.     class Train
  61.     {
  62.         public string Direction;
  63.         public Wagon[] Wagons;
  64.         public int CurrentPassenger;
  65.         public Train(string direction, Wagon[] wagons, int currentPassenger)
  66.         {
  67.             Direction = direction;
  68.             Wagons = wagons;
  69.             CurrentPassenger=currentPassenger;
  70.         }
  71.         public void ShowInfo()
  72.         {
  73.             Console.SetCursorPosition(0, 6);
  74.             Console.WriteLine($"поезд из {Wagons.Length} вагонов перевозит {CurrentPassenger} пассажиров по направлению {Direction} отправлен\n");
  75.             for (int i = 0; i < Wagons.Length; i++)
  76.             {
  77.                 Wagons[i].ShowWagons();
  78.             }
  79.         }
  80.     }
  81.     class Wagon
  82.     {
  83.         public int WagonCount;
  84.         public int WagonCapacity;
  85.         public Wagon(int wagonCount, int wagonCapacity)
  86.         {
  87.             WagonCount = wagonCount;
  88.             WagonCapacity = wagonCapacity;
  89.         }
  90.         public void ShowWagons()
  91.         {
  92.             Console.WriteLine($"Номер вагона - {WagonCount}, вместимость вагона - {WagonCapacity}");
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement