-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParkingSpot.java
58 lines (51 loc) · 1.27 KB
/
ParkingSpot.java
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
/**
* Project 2: ParkingSpot class that has attributes of id, and parkedCar,
* getter methods for its attributes,
* and methods to add and remove a car.
*
* @author Abdurrahman Faqih 104675143
* @version 0.1 10 May 2024
*/
public class ParkingSpot {
// Initialize details
private String id;
private Car parkedCar;
public ParkingSpot(String id) {
this.id = id;
this.parkedCar = null;
}
/**
* Adds a car to the parking spot
* @param car Car to be added to the parking spot
*/
public void addCar(Car car) {
this.parkedCar = car;
}
/**
* Removes a car from the parking spot
*/
public void removeCar() {
this.parkedCar = null;
}
/**
* Gets id of parking spot and returns it
* @return id of parking spot
*/
public String getId() {
return this.id;
}
/**
* Returns whether the parking spot is occupied
* @return true if parkedCar is not null, false otherwise
*/
public boolean isOccupied() {
return this.parkedCar != null;
}
/**
* Returns the parked car object of car parked in parking spot
* @return car parked in parking spot
*/
public Car getParkedCar() {
return this.parkedCar;
}
}