Cheer Board
Implement a class CheerBoard that keeps score at a talent show. The crowd cheers and boos the acts, and the host wants to know at any time who is in front and who is last. Write these methods:
CheerBoard()starts with an empty board.cheer(name)gives the act one point. An act that is not on the board joins it with 1 point.boo(name)takes one point from the act. An act that drops to 0 points leaves the board. Booing an act that is not on the board does nothing.points_of(name)returns the points of the act, or0if it is not on the board.get_leader()returns the name with the most points. If several acts share the most points, it returns the one that comes first in the alphabet. On an empty board it returns"".get_trailer()returns the name with the fewest points among the acts on the board, with the same rule for ties and for an empty board.
The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.
Example 1
CheerBoard()
cheer("bo")
cheer("ada")
cheer("bo")
get_leader() returns "bo"
get_trailer() returns "ada"
boo("ada")
get_trailer() returns "bo"
cheer("cy")
get_trailer() returns "cy"
points_of("ada") returns 0
After three cheers bo has 2 points and ada has 1. A boo takes ada off the board, so bo is both leader and trailer. Then cy joins with 1 point and becomes the trailer.
Constraints
- names are 2 or 3 lowercase letters
- Each test makes
1to40method calls after the constructor.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.