-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParkingSlot.cs
116 lines (95 loc) · 2.21 KB
/
ParkingSlot.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Vehicle and its inherited classes.
public enum VehicleSize { Motorcycle, Compact,Large }
public abstract class Vehicle
{
protected ArrayList<ParkingSpot> parkingSpots =
new ArrayList<ParkingSpot>();
protected String licensePlate;
protected int spotsNeeded;
protected VehicleSize size;
public int getSpotsNeeded()
{
return spotsNeeded;
}
public VehicleSize getSize()
{
return size;
}
/* Park vehicle in this spot (among others,
potentially) */
public void parkinSpot(ParkingSpot s)
{
parkingSpots.add(s);
}
/* Remove vehicle from spot, and notify spot
that it's gone */
public void clearSpots() { ... }
/* Checks if the spot is big enough for the
vehicle (and is available).
This * compares the SIZE only.It does not
check if it has enough spots. */
public abstract boolean canFitinSpot(ParkingSpot spot);
}
public class Bus extends Vehicle
{
public Bus()
{
spotsNeeded = 5;
size = VehicleSize.Large;
}
/* Checks if the spot is a Large. Doesn't check
num of spots */
public boolean canFitinSpot(ParkingSpot spot)
{... }
}
public class Car extends Vehicle
{
public Car()
{
spotsNeeded = 1;
size = VehicleSize.Compact;
}
/* Checks if the spot is a Compact or a Large. */
public boolean canFitinSpot(ParkingSpot spot)
{ ... }
}
public class Motorcycle extends Vehicle
{
public Motorcycle()
{
spotsNeeded = 1;
size = VehicleSize.Motorcycle;
}
public boolean canFitinSpot(ParkingSpot spot)
{ ... }
}
public class ParkingSpot
{
private Vehicle vehicle;
private VehicleSize spotSize;
private int row;
private int spotNumber;
private Level level;
public ParkingSpot(Level lvl, int r, int n,
VehicleSize s)
{ ... }
public boolean isAvailable()
{
return vehicle == null;
}
/* Check if the spot is big enough and is available */
public boolean canFitVehicle(Vehicle vehicle) { ... }
/* Park vehicle in this spot. */
public boolean park(Vehicle v) {..}
public int getRow()
{
return row;
}
public int getSpotNumber()
{
return spotNumber;
}
/* Remove vehicle from spot, and notify
level that a new spot is available */
public void removeVehicle() { ... }
}