`
using System;
using System.Collections.Generic;
using System.Linq;
public class ParkingSystem
{
private readonly char[] sectors = { 'A', 'B', 'C', 'D', 'E', 'F' };
private readonly int maxSpacesPerSector = 50;
private readonly Random random = new Random();
private HashSet occupiedSpots = new HashSet(); // Tablica miejsc zajętych
public ParkingSystem()
{
// Tutaj możesz dodać istniejące miejsca parkingowe do tablicy zajętych miejsc
// occupiedSpots.Add("A1");
// occupiedSpots.Add("B10");
// itd.
}
public string GetRandomParkingSpot()
{
// Tworzenie listy dostępnych miejsc
List<string> availableSpots = new List<string>();
foreach (char sector in sectors)
{
for (int space = 1; space <= maxSpacesPerSector; space++)
{
string spot = $"{sector}{space}";
if (!occupiedSpots.Contains(spot))
{
availableSpots.Add(spot);
}
}
}
// Sprawdzanie czy istnieją dostępne miejsca
if (availableSpots.Count == 0)
{
return "Brak dostępnych miejsc!";
}
// Losowanie miejsca spośród dostępnych
int randomIndex = random.Next(availableSpots.Count);
string randomSpot = availableSpots[randomIndex];
// Dodanie wybranego miejsca do tablicy miejsc zajętych
occupiedSpots.Add(randomSpot);
return randomSpot;
}
}
class Program
{
static void Main(string[] args)
{
ParkingSystem parkingSystem = new ParkingSystem();
// Przykładowe użycie - wyświetlenie losowego miejsca parkingowego
Console.WriteLine("Losowe miejsce parkingowe: " + parkingSystem.GetRandomParkingSpot());
}
Create command which save rand ParkingPlace in db
something like:
` using System; using System.Collections.Generic; using System.Linq;
public class ParkingSystem { private readonly char[] sectors = { 'A', 'B', 'C', 'D', 'E', 'F' }; private readonly int maxSpacesPerSector = 50; private readonly Random random = new Random(); private HashSet occupiedSpots = new HashSet(); // Tablica miejsc zajętych
}
class Program { static void Main(string[] args) { ParkingSystem parkingSystem = new ParkingSystem();
} `