@@ -6,52 +6,173 @@ We'll cover essential components and functionalities, breaking down requirements
6
6
7
7
## Understanding the Requirements
8
8
A parking lot system manages vehicles parking in and out, with different parking spot sizes and rates. Key requirements include:
9
- - ** Vehicle Management:** Handling different types of vehicles .
10
- - ** Spot Management:** Managing various parking spot sizes .
11
- - ** Check-In/Out Process :** Recording the entry and exit of vehicles .
12
- - ** Payment Calculation :** Calculating parking fees .
9
+ - ** Parking Space Management:** Track the availability of parking spaces .
10
+ - ** Vehicle Management:** Handle the entry and exit of vehicles .
11
+ - ** Fee Calculation :** Calculate parking fees based on parking duration .
12
+ - ** Parking Lot Capacity :** Support different types of vehicles with designated spots (e.g., compact, large, handicapped) .
13
13
14
14
## Core Use Cases
15
15
1 . ** Parking a Vehicle:** Assigning spots to vehicles and recording entry time.
16
16
2 . ** Unparking a Vehicle:** Removing a vehicle and calculating the fee.
17
17
3 . ** Spot Availability Check:** Checking for available spots for specific vehicles.
18
+ 4 . ** Handling Different Vehicle Types**
18
19
19
20
## Key Classes:
20
21
- ` ParkingLot ` : Manages the entire parking lot, including floors.
21
22
- ` ParkingFloor ` : Represents individual floors with parking spots.
22
- - ` ParkingSpot ` : Abstract class for specific spot types (e.g., ` CarSpot ` ) .
23
+ - ` ParkingSpot ` : Represents an individual parking spot.
23
24
- ` Vehicle ` : Abstract class for various vehicle types (e.g., ` Car ` ).
25
+ - ` ParkingTicket ` : Represents a parking ticket issued to a vehicle.
26
+ - ` FeeCalculator ` : Calculates parking fees.
24
27
25
28
## Java Implementation
26
29
Here's a simplified version of Java code:
27
30
31
+ ### Vehicle Class
28
32
``` java
29
- class ParkingLot {
30
- private List<ParkingFloor > floors;
33
+ abstract class Vehicle {
34
+ private String licenseNumber;
35
+ protected VehicleType type;
36
+
37
+ public Vehicle (String licensePlate , VehicleType type ) {
38
+ this . licensePlate = licensePlate;
39
+ this . type = type;
40
+ }
41
+
31
42
// Other attributes and methods
32
43
}
33
44
34
- class ParkingFloor {
35
- private List<ParkingSpot > spots;
36
- // Other attributes and methods
45
+ class Car extends Vehicle {
46
+ // Car specific attributes
37
47
}
38
48
39
- abstract class ParkingSpot {
40
- private boolean isAvailable;
41
- private Vehicle vehicle;
42
- // Other attributes and methods
49
+ enum VehicleType {
50
+ COMPACT , LARGE , HANDICAPPED
43
51
}
52
+ ```
53
+ ### ParkingSpot Class
54
+ ``` java
55
+ public class ParkingSpot {
56
+ private String id;
57
+ private VehicleType type;
58
+ private boolean isOccupied;
44
59
45
- class CarSpot extends ParkingSpot {
46
- // Car specific attributes
60
+ public ParkingSpot (String id , VehicleType type ) {
61
+ this . id = id;
62
+ this . type = type;
63
+ this . isOccupied = false ;
64
+ }
65
+
66
+ public void occupySpot () {
67
+ isOccupied = true ;
68
+ }
69
+
70
+ public void freeSpot () {
71
+ isOccupied = false ;
72
+ }
73
+
74
+ // Getters and setters...
47
75
}
76
+ ```
77
+ ### ParkingTicket Class
78
+ ``` java
79
+ import java.util.Date ;
48
80
49
- abstract class Vehicle {
50
- private String licenseNumber;
81
+ public class ParkingTicket {
82
+ private String ticketId;
83
+ private Date issuedAt;
84
+ private Date paidAt;
85
+ private double fee;
86
+
87
+ public ParkingTicket (String ticketId ) {
88
+ this . ticketId = ticketId;
89
+ this . issuedAt = new Date ();
90
+ }
91
+
92
+ public void markPaid (double fee ) {
93
+ this . paidAt = new Date ();
94
+ this . fee = fee;
95
+ }
96
+
97
+ // Getters and setters...
98
+ }
99
+ ```
100
+ ### FeeCalculator Class
101
+ ``` java
102
+ public class FeeCalculator {
103
+ public double calculateFee (Date issuedAt , Date paidAt ) {
104
+ // Assume a method to calculate fee based on issuedAt and paidAt
105
+ return 0.0 ; // Placeholder
106
+ }
107
+ }
108
+ ```
109
+ ### ParkingLot Class
110
+ ``` java
111
+ class ParkingLot {
112
+ private List<ParkingSpot > parkingSpots;
113
+ private List<ParkingTicket > issuedTickets;
114
+
115
+ public ParkingLot () {
116
+ this . parkingSpots = new ArrayList<> ();
117
+ this . issuedTickets = new ArrayList<> ();
118
+ }
119
+
120
+ public ParkingSpot findAvailableSpot (VehicleType type ) {
121
+ // Logic to find an available spot based on vehicle type
122
+ return null ; // Placeholder
123
+ }
124
+
125
+ public ParkingTicket issueTicket (Vehicle vehicle ) {
126
+ ParkingSpot spot = findAvailableSpot(vehicle. getType());
127
+ if (spot != null ) {
128
+ spot. occupySpot();
129
+ ParkingTicket ticket = new ParkingTicket (generateTicketId());
130
+ issuedTickets. add(ticket);
131
+ return ticket;
132
+ }
133
+ return null ;
134
+ }
135
+
136
+ public void processPayment (ParkingTicket ticket , double fee ) {
137
+ ticket. markPaid(fee);
138
+ // Additional logic for processing payment
139
+ }
140
+
141
+ private String generateTicketId () {
142
+ return " TICKET_" + System . currentTimeMillis();
143
+ }
144
+
145
+ // Other necessary methods...
146
+ }
147
+ ```
148
+ ### ParkingFloor
149
+ ``` java
150
+ class ParkingFloor {
151
+ private List<ParkingSpot > spots;
51
152
// Other attributes and methods
52
153
}
53
154
54
- class Car extends Vehicle {
155
+ public class ParkingSpot {
156
+ private String id;
157
+ private VehicleType type;
158
+ private boolean isOccupied;
159
+
160
+ public ParkingSpot (String id , VehicleType type ) {
161
+ this . id = id;
162
+ this . type = type;
163
+ this . isOccupied = false ;
164
+ }
165
+
166
+ public void occupySpot () {
167
+ isOccupied = true ;
168
+ }
169
+
170
+ public void freeSpot () {
171
+ isOccupied = false ;
172
+ }
173
+ }
174
+
175
+ class CarSpot extends ParkingSpot {
55
176
// Car specific attributes
56
177
}
57
178
```
0 commit comments