Skip to content

Commit c1928c0

Browse files
committed
update readme and add repository logo
1 parent 09cdbb2 commit c1928c0

File tree

3 files changed

+146
-20
lines changed

3 files changed

+146
-20
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# awesome-low-level-design
1+
<p align="center">
2+
<img src="images/lld-repo-logo.png" width="350" height="200">
3+
</p>
4+
<p align="center">
5+
<a href="https://www.linkedin.com/in/ashishps1/">LinkedIn</a> | <a href="https://www.youtube.com/@ashishps_1/videos">YouTube</a> | <a href="https://twitter.com/ashishps_1">X</a> | <a href="https://newsletter.ashishps.com/">Newsletter</a>
6+
</p>
27
This repository contains low level design (LLD) resources to improve object oriented design (OOD) skills and prepare for interviews.
38

49
## Fundamental Concepts

images/lld-repo-logo.png

99.7 KB
Loading

problems/parking-lot.md

Lines changed: 140 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,173 @@ We'll cover essential components and functionalities, breaking down requirements
66

77
## Understanding the Requirements
88
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).
1313

1414
## Core Use Cases
1515
1. **Parking a Vehicle:** Assigning spots to vehicles and recording entry time.
1616
2. **Unparking a Vehicle:** Removing a vehicle and calculating the fee.
1717
3. **Spot Availability Check:** Checking for available spots for specific vehicles.
18+
4. **Handling Different Vehicle Types**
1819

1920
## Key Classes:
2021
- `ParkingLot`: Manages the entire parking lot, including floors.
2122
- `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.
2324
- `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.
2427

2528
## Java Implementation
2629
Here's a simplified version of Java code:
2730

31+
### Vehicle Class
2832
```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+
3142
// Other attributes and methods
3243
}
3344

34-
class ParkingFloor {
35-
private List<ParkingSpot> spots;
36-
// Other attributes and methods
45+
class Car extends Vehicle {
46+
// Car specific attributes
3747
}
3848

39-
abstract class ParkingSpot {
40-
private boolean isAvailable;
41-
private Vehicle vehicle;
42-
// Other attributes and methods
49+
enum VehicleType {
50+
COMPACT, LARGE, HANDICAPPED
4351
}
52+
```
53+
### ParkingSpot Class
54+
```java
55+
public class ParkingSpot {
56+
private String id;
57+
private VehicleType type;
58+
private boolean isOccupied;
4459

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...
4775
}
76+
```
77+
### ParkingTicket Class
78+
```java
79+
import java.util.Date;
4880

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;
51152
// Other attributes and methods
52153
}
53154

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 {
55176
// Car specific attributes
56177
}
57178
```

0 commit comments

Comments
 (0)