-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
ParkingSpot.cs
55 lines (47 loc) · 1.21 KB
/
ParkingSpot.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using ParkingLot.VehicleTypes;
using System;
namespace ParkingLot
{
public class ParkingSpot
{
private readonly int spotNumber;
private readonly VehicleType vehicleType;
private Vehicle parkedVehicle;
public ParkingSpot(int spotNumber, VehicleType vehicleType)
{
this.spotNumber = spotNumber;
this.vehicleType = vehicleType;
}
public bool IsAvailable()
{
return parkedVehicle == null;
}
public void ParkVehicle(Vehicle vehicle)
{
if (IsAvailable() && vehicle.GetVehicleType() == vehicleType)
{
parkedVehicle = vehicle;
}
else
{
throw new ArgumentException("Invalid vehicle type or spot already occupied.");
}
}
public void UnparkVehicle()
{
parkedVehicle = null;
}
public VehicleType GetVehicleType()
{
return vehicleType;
}
public Vehicle GetParkedVehicle()
{
return parkedVehicle;
}
public int GetSpotNumber()
{
return spotNumber;
}
}
}