Capstone 7 — Vehicle Rental System¶
Scope: a term's work · Prerequisites: Modules 1–15
1. Problem statement¶
A vehicle rental company has a fleet of cars, vans and motorcycles, rented from several branches. A rental occupies one vehicle for a period, and returns it to a branch that may not be the one it left from.
Pricing depends on the vehicle category, the rental duration, the distance driven, the driver's age and any extras (child seat, additional driver, insurance upgrade). Extra charges apply on return: late returns, excess mileage, missing fuel, and damage. A vehicle goes out of service for maintenance, which must not be confused with being rented, and a vehicle may be written off.
The system runs at a branch desk and must be able to answer "what is available at this branch for these dates?" quickly.
2. Actors¶
| Actor | What they do | What the system owes them |
|---|---|---|
| Customer | Reserves, collects, returns, disputes charges | A quoted price, and a return statement that explains every charge |
| Branch clerk | Checks vehicles in and out, records condition and mileage | Availability that is correct, and a record that survives a dispute |
| Fleet manager | Schedules maintenance, writes vehicles off, moves them between branches | A fleet view with each vehicle's state and no ambiguous ones |
| Accountant | Reads revenue per category and branch | Totals that reconcile and never change after closing a rental |
3. Use cases¶
- Add vehicles of several categories; each vehicle belongs to a branch.
- Check availability at a branch for a category and a date range.
- Quote a price for a rental, itemised.
- Make a reservation, collect a vehicle, and return it with the mileage and fuel level.
- Compute the return charges: extra days, excess mileage, fuel, extras.
- Put a vehicle into maintenance for a range, and take it out.
- Move a vehicle between branches.
- Write off a vehicle, keeping its rental history visible.
- List overdue rentals and vehicles needing servicing.
- Save and load everything; refuse a corrupted file with a line number and no partial state.
4. Suggested classes¶
| Class | Responsibility, in one sentence | Notes |
|---|---|---|
DateRange |
A half-open range of days, with overlap | Reused from the hotel-style domain; a value type |
Vehicle |
One physical vehicle: registration, category, branch, state | Owns its state, which is more than rented/free |
VehicleCategory |
What is shared by a category: base rate, mileage rate, seating | Configuration carrier |
VehicleState |
Whether the vehicle is available, rented, in maintenance or written off | The ambiguity this project must not have |
MaintenanceJob |
A vehicle out of service for a range, with a reason | Overlaps availability exactly like a rental |
Reservation |
A customer's claim on a category at a branch for a range | May be fulfilled by any matching vehicle |
Rental |
One vehicle out with one customer, from a collection to a return | Aggregates vehicle and customer |
ReturnReport |
What was found at return: mileage, fuel, damage, charges | Owns its charge lines |
PricingPolicy |
Turns category, duration, mileage, age and extras into a total | An interface: the thing that varies |
ExtraChargePolicy |
Turns a return report into extra charges | Another interface, so charges compose |
Fleet |
Owns vehicles and answers availability | Where the booking index lives |
Branch |
A location with a fleet subset | Owns no vehicles; references them |
The class worth the most marks is VehicleState — not the enum, but the design decision around it.
A vehicle can be rented, in maintenance, in transit between branches or written off, and each of those is
incompatible with the others. Getting that from "isRented: bool" to a state with guarded transitions is
the project's central design task, and the report should show what changes were expensive under the naive
version.
5. Relationships¶
Fleet ◆── vector<Vehicle> composition
Branch ────> Vehicle association: a branch references vehicles it does not own
Vehicle ◆── VehicleState composition: the state is the vehicle's current condition
Vehicle ◆── vector<MaintenanceJob> composition: jobs belong to the vehicle
Rental ◆── DateRange composition
Rental ────> Vehicle association
Rental ────> Customer association
ReturnReport ◆── vector<ChargeLine> composition
Rental ◆── ReturnReport composition: the report belongs to the rental
Fleet ┈┈> PricingPolicy dependency, injected
ReturnReport ┈┈> ExtraChargePolicy dependency, injected
6. Design constraints¶
- A vehicle is in exactly one state, and the transitions are guarded: a rented vehicle cannot be put into maintenance, a written-off one cannot be rented. State the rule once, and demonstrate a refusal.
- Maintenance occupies the vehicle for a range, and availability must account for it — the bug that ships a car that is in the workshop.
- A reservation is for a category, not a registration, unless the customer paid for a specific vehicle; say which your design does and why.
- A quotation is itemised and frozen: returning a vehicle must not reprice the base rental, only add the documented extras.
- Pricing and extra charges are separate policies, because they vary independently and compose.
- Money in integer pence; distance in integer kilometres, and fuel as a fraction with a documented representation.
- Availability must not be a full linear scan in the design you submit, or the report must say what it costs and what you would change.
- Format: documented text format with a version marker and an escape rule; a later-version file refused, not misread.
7. Milestones¶
| # | Milestone | Done when |
|---|---|---|
| 1 | Design | Diagram; the vehicle state model with its transitions written out; the availability structure chosen |
| 2 | Fleet and branches | Vehicles, categories and branches; state transitions guarded and tested |
| 3 | Availability | "Free at this branch for these dates" is correct, accounting for rentals and maintenance |
| 4 | Rentals and pricing | Quote, collect, return; base price frozen; extras computed at return by a second policy |
| 5 | Persistence | Documented format; round trip preserving rentals and charges; three hand-edited corruptions rejected with line numbers |
| 6 | Tests and report | Boundaries and failures asserted; a deliberate bug caught; the state-model decision evaluated; the reversal named with its cost |
8. Minimum requirements¶
- [ ] Vehicles with a state, categories and branches, each with invariants enforced in its own class
- [ ] Guarded state transitions, with a refusal that names the current state — demonstrated
- [ ] Availability at a branch for a category and range, accounting for rentals and maintenance
- [ ] Quote, collect and return, with an itemised quotation frozen at collection
- [ ] Base pricing varying by category, duration, mileage, driver age and extras, from an injected policy
- [ ] Return charges for extra days, excess mileage, fuel and damage, from a second injected policy
- [ ] Rental history preserved when a vehicle is written off — a report still lists past rentals
- [ ] Persistence with a version marker and escape rule; a round trip preserving every rental, including an empty fleet history
- [ ] Three hand-edited corruptions rejected with line numbers, leaving the loaded state untouched
- [ ] At least two patterns, each justified by a named requirement; one declined, with the reason
- [ ] Tests with assertions covering invariants, boundaries and failure paths
- [ ] No warnings with
-Wall -Wextra -Werror
9. Advanced requirements¶
- [ ] A fourth category added with no edits to existing code — the file count in the report
- [ ] Vehicle moves between branches, with the availability effect at both ends
- [ ] A late-return charge that escalates by hour, with the rule stated and boundaries tested
- [ ] Availability measured: your structure against a naive scan, at two fleet sizes, with the numbers in the report
- [ ] Overdue rentals report, and a notification to the customer
- [ ] Damage charges from a list of damage kinds with separate rates
- [ ] An accountant's export of revenue by category and branch, to CSV behind the same interface
10. Testing requirements¶
- Invariants: exactly one state per vehicle; no overlapping rental and maintenance on one vehicle; a quotation is unchanged at return; total charges equal the sum of the lines
- Boundaries: a one-day rental; a rental ending the day maintenance begins; mileage exactly at the included limit; a return one minute before and after midnight; a zero-distance rental
- Failure paths: renting an unavailable vehicle; returning a vehicle not rented; putting a rented vehicle into maintenance; quoting with a negative duration; loading a truncated file
- Round trip: rentals, quotations and charges preserved exactly, including an empty history and a rental spanning a month boundary
- One deliberate bug (for example, ignoring maintenance in availability), caught by the availability test, with the failing assertion kept
11. Extension ideas¶
- A fleet utilisation report, and the complexity of computing it from your index.
- Waiting lists per category at a branch, with notifications.
- Fuel policy variants (full-to-full, full-to-empty) as another policy, injected.
- Corporate accounts with negotiated rates — a second dimension of pricing, and a measurement of the change cost.
- Servicing schedules based on mileage thresholds, with a notification when one is due.
- Dynamic pricing by season, composed with the existing policy — count the files.
12. Evaluation checklist¶
- [ ] The diagram matches the declarations, including multiplicities
- [ ] A vehicle's state is unambiguous and every transition is guarded — demonstrated
- [ ] Maintenance is accounted for in availability — demonstrated by a test that tries to rent a workshop vehicle
- [ ] The quotation is itemised and frozen; extras are a separate, injected policy
- [ ] Money is integer pence and distance is integer kilometres, with fuel's representation documented
- [ ] Availability's cost is stated, with a measurement and the rejected alternative
- [ ] Written-off vehicles keep their history — demonstrated
- [ ] The round trip preserves rentals and charges, including an empty history — output pasted
- [ ] Three corruptions rejected with line numbers, leaving the loaded state untouched
- [ ] The suite fails when a deliberate bug is introduced
- [ ] One pattern considered and declined, in writing
- [ ] The report names the decision I would reverse and the cost of reversing it
Related: Capstone options · Projects and the rubric · Module 16 — Capstone · Module 7 — Polymorphism