CSE Roadmap

Core tier · about 4 hours · 6 parts

Part 2 of 6 · 2 min read

Requirements

Who paid, who shares, who owes.

Think of four friends on a trip. Asha pays for dinner. Ben pays for the taxi. Chen pays for tickets. At the end, nobody wants to check thirty receipts. They want one answer: who pays whom, and how much.

Questions and the answers assumed here:

  1. What is an expense? An amount, a payer and the people who share it.
  2. How is it shared? Equally, by exact amounts, or by percentages.
  3. What does the app keep? For each person, a net balance: positive means others owe them, negative means they owe others.
  4. How do people settle? One person pays another, which changes both balances.
  5. Can the debts be simplified? Yes. The app can list a short set of payments that clears everyone.
  6. Out of scope: currencies, groups with separate books, and receipts.

The numbered requirements:

  • R1. Members can be added.
  • R2. An expense has a payer, a total and a list of sharers, and is split by a chosen rule.
  • R3. The shares of an expense always add up to its total exactly.
  • R4. A bad split is refused with a clear message, and changes nothing.
  • R5. Each person has a net balance, and the sum of all balances is always zero.
  • R6. A settlement moves money between two people.
  • R7. A simplify method lists a small set of payments that settles everyone.

Net balance

A net balance is the total a person is owed minus the total the person owes. A positive balance means the person gets money back. A negative balance means the person must pay.

Example: Asha paid 100 and her own share was 33.34, so her balance is plus 66.66.

Money is stored as cents in a long, not as a double. A double cannot hold 0.10 exactly, so sums drift by tiny amounts, and a ledger that must balance to the cent cannot allow that. Whole cents make every sum exact.

Check yourself: 1. What does a negative balance mean? 2. Why must the sum of all balances be zero? 3. Why are cents stored in a long?