Object-Oriented Delivery Cost and Payment Accounting System
Context
You are designing a small in-memory service to track delivery costs for drivers who are paid hourly. Deliveries are recorded with start and end timestamps. The system must compute total cost to date, support marking accrued costs up to a timestamp as paid, and report remaining unpaid amounts.
Make explicit assumptions about time interval semantics (inclusive/exclusive), how to prorate partial hours, and how to round currency.
Requirements
-
Drivers register with an hourly rate (and may be updated):
-
RegisterDriver(driverId, hourlyRate)
-
Record deliveries:
-
RecordDelivery(driverId, startTime, endTime)
-
Aggregate queries:
-
getTotalCost() → sum over all deliveries of hourlyRate(driverId) × duration
-
payUpTo(timestamp) → mark all accrued costs up to timestamp as paid. If a delivery overlaps the timestamp, only the portion up to timestamp is paid (logically split at the timestamp).
-
getTotalUnpaid() → total remaining unpaid amount after all payUpTo calls.
Deliverables
-
Class design and core data structures
-
Method signatures
-
Define: interval inclusivity/exclusivity; partial hours handling and rounding strategy
-
Discuss: idempotency, time zones, numeric precision, and time/space complexity