- Design valet car parking system to manage a parking space and its revenue as vehicles enter/exit
- The first line indicates the number of parking slots for Cars and Motorcycles respectively in the parking lot.
- For each subsequent line, vehicle may:
- enter the space with
Enter <motorcycle|car> <vehicle number> <entryTime>
- exit the space with
Exit <vehicle number> <exitTime>
- enter the space with
- For more details, See the section on
Flow Structure
Prerequisites: Node and NPM
Steps:
npm install
npm run start
(optional) npm run test
📦valet-car-parking-system
┣ 📂src
┃ ┗ 📜index.js
┃ ┗ 📂constants
┃ ┗ 📂entities
┃ ┗ 📂handler
┃ ┗ 📂input
┣ 📜.gitignore
┣ 📜 readme.md
┣ 📜package-lock.json
┗ 📜package.json
- ParkingLot:
🅿️ - carLot & motorCycleLot in array structure. Eg. [0,0,0]
- Vehicle: 🚗
- contains vehicle details such as car type, car plate number, parking lot assigned, and entry time stamp
- Read line by line from input-file
- First Line: create new
ParkingLot
object and initialize available parking lot in array structure - Subsequent Lines:
- if first word of the line = 'Enter' -> create new
Vehicle
and store it in the first available car lot ofParkingLot
- if first word of the line = 'Exit' -> find car plate number from
Vehicle
and remove it from the car lot ofParkingLot
- if first word of the line = 'Enter' -> create new
📌 consolidating all in a single handler to allow future enhancement
Error that has been handled includes:
- Input Error
- Invalid car type upon entering (Allowing only 2 types. To allow new vehicle & price in the future)
- Invalid vehicle plate upon exiting
- Exit Time before entry time error
- Automated unit test for all methods
- Manual test on index.js to simulate different input files
- Flexibility to switch between different input files
- Unit test on index.js to input different input file and file types
- OutputHandler to handle all console.log