Courses / Machine Coding and Low-Level Design in TypeScript / Chapter 15
Module 6 · Design problems III: meetings, cinemas and car rental · Chapter 15 of 28
Car Rental: Fleet, Reservations, Pricing and Returns
Builds on Solving a Design Problem: Requirements to Tested Code in Six Steps, Design Patterns in TypeScript: Creational, Structural and Behavioural and Movie Ticket Booking: Shows, Seat Holds and No Double Booking. Next up: ATM: Sessions, PIN Checks, Cash Dispensing and Reversals.
Part 1 · Requirements
What the rental desk must do
A rental company promises a category of car for dates weeks ahead, then hands over whichever car is in the lot that morning. This chapter builds that logic for a Goa operator with an airport branch and a city branch.
A requirement is a sentence about the system that someone can check. Functional requirements say what the system does, and we write them before any class exists. For the Goa operator, they are these.
- Each branch has a fleet of cars. A car has a category (hatchback, sedan or SUV) and a status: in the lot, rented out or in the workshop.
- A customer asks whether a category is free at a branch for a date range, and reserves a category for those dates, with optional add-ons such as a child seat or a GPS unit.
- The price is fixed when the reservation is made: a rate per day, plus a fixed amount per day for each add-on.
- At pickup, the counter gives the customer a car of the booked category that is in the lot.