Advertisement
Askor

Hw32

Nov 15th, 2021 (edited)
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.62 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.  
  7. namespace Train
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Train train = new Train();
  14.             TicketOffice tickets = new TicketOffice();
  15.             Railstation railstation = new Railstation(train, tickets);
  16.            
  17.             Console.SetCursorPosition(0,5);
  18.             train.CreateWay();
  19.             tickets.SellTickets();
  20.             train.Create(tickets);
  21.             railstation.SendTrain();
  22.             Console.ReadKey();
  23.         }
  24.     }
  25.  
  26.     class Railstation
  27.     {
  28.         private Train _train;
  29.         private TicketOffice _tickets;
  30.  
  31.         public Railstation(Train train, TicketOffice tickets)
  32.         {
  33.             _train = train;
  34.             _tickets = tickets;
  35.         }
  36.         public void SendTrain()
  37.         {
  38.             Console.WriteLine("Чтобы отправить поезд нажмите любую кнопку");
  39.             Console.ReadKey();
  40.             Console.Clear();
  41.             Console.SetCursorPosition(0,0);
  42.             Console.WriteLine($"Поезд по маршруту {_train.Departure} - {_train.Destination} отправлен. Кол-во пассажиров - {_tickets.Tickets}. Кол-во вагонов - {_train.CountVans}, вместимостью - {_train.VanCapacity}");
  43.         }
  44.     }
  45.  
  46.     class Train
  47.     {
  48.         private bool _isVanTypeSelected;
  49.  
  50.         public int CountVans { get; private set; }
  51.         public int VanCapacity { get; private set; }
  52.         public string Departure { get; private set; }
  53.         public string Destination { get; private set; }
  54.  
  55.         public void CreateWay()
  56.         {
  57.             Console.WriteLine("Введите пункт отправления:");
  58.             Departure = Console.ReadLine();
  59.             Console.WriteLine("Введите пункт прибытия:");
  60.             Destination = Console.ReadLine();
  61.         }
  62.  
  63.         private void SelectVanType()
  64.         {
  65.             string userInput;
  66.             int vanType15 = 15;
  67.             int vanType25 = 25;
  68.  
  69.             Console.WriteLine("Выберите тип вагонов 1 - 15 мест | 2 - 25 мест");
  70.             userInput = Console.ReadLine();
  71.  
  72.             switch (userInput)
  73.             {
  74.                 case "1":
  75.                     VanCapacity = vanType15;
  76.                     _isVanTypeSelected = true;
  77.                     break;
  78.                 case "2":
  79.                     VanCapacity = vanType25;
  80.                     _isVanTypeSelected = true;
  81.                     break;
  82.                 default:
  83.                     Console.WriteLine("Такого типа нет.");
  84.                     _isVanTypeSelected = false;
  85.                     break;
  86.             }
  87.         }
  88.  
  89.         public void Create(TicketOffice tickets)
  90.         {
  91.             do
  92.             {
  93.                 SelectVanType();
  94.             }
  95.             while(_isVanTypeSelected == false);
  96.  
  97.             if (tickets.Tickets % VanCapacity != 0)
  98.             {
  99.                 CountVans = tickets.Tickets / VanCapacity + 1;
  100.             }
  101.             else
  102.             {
  103.                 CountVans = tickets.Tickets / VanCapacity;  
  104.             }
  105.         }
  106.     }
  107.  
  108.     class TicketOffice
  109.     {
  110.         public int Tickets { get; private set; }
  111.        
  112.         public void SellTickets()
  113.         {
  114.             Random random = new Random();
  115.             Tickets = random.Next(100);
  116.             Console.WriteLine($"Продано билетов - {Tickets}");
  117.         }
  118.     }
  119. }
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement