Tally Counter
Implement a class TallyCounter that keeps tally marks next to names, like a clipboard at a club vote. Write these methods:
TallyCounter()starts with no marks for anyone.mark(name)adds one mark fornameand returns how many marksnamehas now.count_for(name)returns how many marksnamehas. A name that was never marked has0.erase(name)removes one mark fromnameand returnstrue. Ifnamehas no marks, nothing changes and it returnsfalse.get_total()returns the number of marks over all names together.
The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.
Example 1
TallyCounter()
mark("ann") returns 1
mark("bo") returns 1
mark("ann") returns 2
count_for("ann") returns 2
erase("bo") returns true
count_for("bo") returns 0
get_total() returns 2
ann gets two marks and bo one. Erasing bo works and leaves bo at 0, so the total is 2.
Constraints
- Each test makes
1to40method calls after the constructor. nameis1to8lowercase letters.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.