Prototype: splitEqual(total,participants) requires total>=0 and distinct nonempty names in a nonempty list; return lexically sorted Map<String,Long> shares. Divide equally, giving the first total%count sorted names one extra cent. Preserve input.

Final: ExpenseSharing copies fixed valid members and starts all at zero. addExpense requires nonempty operation ID, positive total, group payer, and distinct nonempty participant subset; payer may be excluded. Credit payer total and debit shares. settle requires two distinct members and positive amount bounded by debtor debt and creditor credit. Both methods validate structure, then recognize exact prior success (false) or conflicting ID/method (raise), then apply balance checks. Failures consume no ID. Participant order is ignored for expense identity. balances is fresh lexical map including zero values, positive means owed. suggestSettlements greedily pairs alphabetic debtors/creditors on copies with minimum current amount, omits zeros, returns Settlement values without applying them.

The complete public API is in Exercise.java. All domain classes are public static nested classes of Exercise; construct them as new Exercise.ClassName(...). Do not implement a solution in the test runner. Each instance owns independent state. Unless explicitly allowed, null inputs are outside the domain. Failed operations leave state unchanged; validation happens before mutation.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.

Java runs on this device with CheerpJ 4.3.