Skip to main content

Practice · 2 of 3

The register with a running balance

CHALLENGE
Difficulty: advanced+25 XP

Implement the Register class (a checkout register). scan(price) adds to the amount owed. pay(cash) records cash received — the register accepts payment **larger than owed** (change is owed back). changeDue() returns how much change the customer must receive (cash received minus amount owed, never negative; 0 while still owing). The register starts empty.

Back to lesson: Practice: State machine lab