This commit is contained in:
Debug_pro
2026-03-11 21:46:43 +03:00
commit 1da0dd309b
9 changed files with 685 additions and 0 deletions

52
BusQueueManager.cs Normal file
View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab8
{
public class BusQueueManager
{
private readonly Queue<string> _queue = new Queue<string>();
public List<string> Passengers => _queue.ToList();
public string ExecuteCommand(string input)
{
string[] parts = input.Trim().Split(' ', 2);
string command = parts[0].ToLower();
switch (command)
{
case "arrive":
if (parts.Length < 2 || string.IsNullOrWhiteSpace(parts[1]))
return "Ошибка: не указано имя пассажира.";
string passenger = parts[1].Trim();
_queue.Enqueue(passenger);
return $"Пассажир {passenger} добавлен в очередь.";
case "board":
if (_queue.Count == 0)
return "Ошибка: очередь пуста.";
string boarded = _queue.Dequeue();
return $"Пассажир {boarded} сел в автобус.";
case "next":
if (_queue.Count == 0)
return "Ошибка: очередь пуста.";
return $"Следующий пассажир: {_queue.Peek()}";
case "clear":
_queue.Clear();
return "Очередь очищена.";
default:
return $"Ошибка: неизвестная команда \"{command}\".";
}
}
}
}