1. Problem Statment
Design a Parking lot which can hold n
Cars. Every car been issued a ticket for a slot and the slot been assigned based on the nearest to the entry. The system should also return some queries such as:
- Registration numbers of all cars of a particular colour.
- Slot number in which a car with a given registration number is parked.
- Slot numbers of all slots where a car of a particular colour is parked.
Disclaimer
This solution is for reference purpose. Please, do not copy-paste it. Companies are smart enough to catch if you are cheating. If your solution got rejected due to this we're not responsible for it.
2. Solution Approach
A car consist of Registration number, slot number and it's colour. Likewise our Parking Lot consist slots. For not making it too complicated, I choose a python dictionary for storing cars on slots and implemented the functionalities as accordingly.
The solution of above problem statement is available here. You can directly download this solution from here.
3. Supported Commands
-
create_parking_lot
<n
>
To create a Parking lot. Wheren
is the size of the parking lot -
park
<registration_number
> <colour
>
To park the car in the parking lot and prints the allocated slot in the parking lot. Whereregistration_number
is given registration number for the car andcolour
is given colour for the car -
leave
<slot
>
To leave the parking lot from desired slot and prints the leaving slot. given slot number. Whereslot
is given sloat number -
status
To check the status of Parking Lot -
slot_numbers_for_cars_with_colour
<colour
>
To prints the registration number of the cars for the given colour. Wherecolor
is given colour -
slot_number_for_registration_number
<registration_number
>
prints the slot number of the cars for the given number. Whereregistration_number
is given registration number. -
registration_numbers_for_cars_with_colour
<colour
>
To prints the slot number of the cars for the given colour. Wherecolour
is given colour.
4. Running Application
4.1 Running the application in File mode:
./ParkingLot.py input.txt
4.2 Running the application in Interactive mode:
./ParkingLot.py
5. Test Cases
- Total number of test cases - 14
- Code coverage - 86%
5.1 For running the tests
python Tests.py
5.2 For calculating code coverage
coverage run Tests.py
coverage report
6. Running the application in a Docker Container
Build the image:
docker build -t parkinglot:1.0 .
6.1 Running the application in Interactive mode:
docker run -it parkinglot:1.0 ./ParkingLot.py
6.2 Running the application in File mode:
docker run -it parkinglot:1.0 ./ParkingLot.py input.txt