upload
This commit is contained in:
52
BusQueueManager.cs
Normal file
52
BusQueueManager.cs
Normal 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}\".";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user