Skip to content

Commit 63797a2

Browse files
committed
🔧 Adding LLD Example for Parking Garage
1 parent 39735af commit 63797a2

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

07 LLD Interview Questions/Parking_Garage/PakingLot.py renamed to 07 LLD Interview Questions/Parking_Garage/ParkingLot.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import ParkingSpot
2-
import Ticket
3-
import SpotType
4-
import Vehicle
1+
from ParkingSpot import ParkingSpot
2+
from Ticket import Ticket
3+
from SpotType import SpotType
4+
from Vehicle import Vehicle
55

6-
class parkingLot:
6+
7+
class ParkingLot:
78
def __init__(self):
89
self.spots: list[ParkingSpot] = []
9-
self.active_tickets: dict[str, Ticket] ={}
10+
self.active_tickets: dict[str, Ticket] = {}
1011

1112
def add_spot(self, spot: ParkingSpot):
1213
self.spots.append(spot)
@@ -26,13 +27,14 @@ def park_vehicle(self, vehicle: Vehicle, spot_type: SpotType) -> Ticket:
2627
spot.assign_vehicle(vehicle)
2728
ticket = Ticket(vehicle, spot)
2829
self.active_tickets[ticket.ticket_id] = ticket
30+
return ticket
2931

3032
def unpark_vehicle(self, ticket_id: str):
3133
ticket = self.active_tickets.get(ticket_id)
3234
if not ticket:
3335
raise Exception("Invalid ticket Id")
3436
ticket.close()
35-
free = ticket.get_fee()
36-
ticket.spot_remove_vehicle()
37+
free = ticket.get_fees()
38+
ticket.spot.remove_vehicle()
3739
del self.active_tickets[ticket_id]
3840
return free

07 LLD Interview Questions/Parking_Garage/ParkingSpot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import SpotType
2-
import Vehicle
1+
from SpotType import SpotType
2+
from Vehicle import Vehicle
33

44
class ParkingSpot:
55
def __init__(self, spot_id: str, spot_type: SpotType):
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from ParkingLot import ParkingLot
2+
from ParkingSpot import ParkingSpot
3+
from Vehicle import Vehicle
4+
from Ticket import Ticket
5+
from SpotType import SpotType
6+
7+
if __name__ == "__main__":
8+
9+
# create lot and add spots
10+
lot = ParkingLot()
11+
lot.add_spot(ParkingSpot("S1", SpotType.COMPACT))
12+
lot.add_spot(ParkingSpot("S1", SpotType.LARGE))
13+
lot.add_spot(ParkingSpot("S1", SpotType.REGULAR))
14+
15+
# Park Vehicle
16+
17+
vehicle = Vehicle("KA-01-AB-1234")
18+
ticket = lot.park_vehicle(vehicle, SpotType.REGULAR)
19+
print(f"Vehicle parked. Ticket ID: {ticket.ticket_id}")
20+
21+
# Unpark a vehicle
22+
23+
fee = lot.unpark_vehicle(ticket.ticket_id)
24+
print(f"Vehicle unparked. Fee: {fee}")

07 LLD Interview Questions/Parking_Garage/Ticket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Vehicle
2-
import ParkingSpot
2+
from ParkingSpot import ParkingSpot
33
import uuid
44
from datetime import datetime
55

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from ParkingLot import ParkingLot
2+
from ParkingSpot import ParkingSpot
3+
from Vehicle import Vehicle
4+
from Ticket import Ticket
5+
from SpotType import SpotType

0 commit comments

Comments
 (0)