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 Train
- {
- class Program
- {
- static void Main(string[] args)
- {
- Train train = new Train();
- TicketOffice tickets = new TicketOffice();
- Railstation railstation = new Railstation(train, tickets);
- Console.SetCursorPosition(0,5);
- train.CreateWay();
- tickets.SellTickets();
- train.Create(tickets);
- railstation.SendTrain();
- Console.ReadKey();
- }
- }
- class Railstation
- {
- private Train _train;
- private TicketOffice _tickets;
- public Railstation(Train train, TicketOffice tickets)
- {
- _train = train;
- _tickets = tickets;
- }
- public void SendTrain()
- {
- Console.WriteLine("Чтобы отправить поезд нажмите любую кнопку");
- Console.ReadKey();
- Console.Clear();
- Console.SetCursorPosition(0,0);
- Console.WriteLine($"Поезд по маршруту {_train.Departure} - {_train.Destination} отправлен. Кол-во пассажиров - {_tickets.Tickets}. Кол-во вагонов - {_train.CountVans}, вместимостью - {_train.VanCapacity}");
- }
- }
- class Train
- {
- private bool _isVanTypeSelected;
- public int CountVans { get; private set; }
- public int VanCapacity { get; private set; }
- public string Departure { get; private set; }
- public string Destination { get; private set; }
- public void CreateWay()
- {
- Console.WriteLine("Введите пункт отправления:");
- Departure = Console.ReadLine();
- Console.WriteLine("Введите пункт прибытия:");
- Destination = Console.ReadLine();
- }
- private void SelectVanType()
- {
- string userInput;
- int vanType15 = 15;
- int vanType25 = 25;
- Console.WriteLine("Выберите тип вагонов 1 - 15 мест | 2 - 25 мест");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "1":
- VanCapacity = vanType15;
- _isVanTypeSelected = true;
- break;
- case "2":
- VanCapacity = vanType25;
- _isVanTypeSelected = true;
- break;
- default:
- Console.WriteLine("Такого типа нет.");
- _isVanTypeSelected = false;
- break;
- }
- }
- public void Create(TicketOffice tickets)
- {
- do
- {
- SelectVanType();
- }
- while(_isVanTypeSelected == false);
- if (tickets.Tickets % VanCapacity != 0)
- {
- CountVans = tickets.Tickets / VanCapacity + 1;
- }
- else
- {
- CountVans = tickets.Tickets / VanCapacity;
- }
- }
- }
- class TicketOffice
- {
- public int Tickets { get; private set; }
- public void SellTickets()
- {
- Random random = new Random();
- Tickets = random.Next(100);
- Console.WriteLine($"Продано билетов - {Tickets}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement