Problem statement
Design the object model and core APIs for an installment-plan (EMI) engine that splits a financed purchase into a schedule of periodic payments, tracks what has been paid, and handles early payoff and missed payments.
Operating context. A purchase of principal P is financed over N periods at an interest rate. The engine builds an amortization schedule where each installment is a principal portion plus an interest portion. Incoming payments are allocated across outstanding installments (oldest first) by a configurable policy. The engine also supports a prepayment (which either shortens the term or lowers future installments), a late fee when a due date passes unpaid, and a payoff quote for settling the remaining balance as of a date. The interest method is pluggable (flat versus reducing-balance). Everything runs in a single process.
Out of scope. Credit scoring and underwriting, payment collection or gateway integration, a persistence layer, regulatory disclosure documents, and multi-currency.
What to produce. The class hierarchy (LoanAccount, Installment, AmortizationSchedule, an interest method, a payment-allocation policy, a late-fee policy, a Clock), the public APIs each exposes, the amortization computation, and the installment state machine (scheduled, due, partially paid, paid, overdue). Be explicit about how the schedule conserves the exact principal despite rounding, and how a prepayment reshapes the remaining schedule.
Must do 5
Functional requirements
- Generate an amortization schedule of N installments from principal, rate, and term, splitting each into principal and interest.
- Apply a payment, allocating it across outstanding installments by the configured policy and updating balances.
- Produce a payoff quote to settle the entire remaining balance as of a given date.
- Apply a late fee and mark an installment overdue once its due date passes unpaid.
- Handle a prepayment by either shortening the term or lowering future installments per the account's configuration.