Coffee Stamp Cards
Implement a class StampCards for a coffee shop: a customer gets one stamp for each drink they pay for, and once they have goal stamps their next drink is free. Write these methods:
StampCards(goal)starts with no customers.buy(customer)sells one drink tocustomer. If they havegoalstamps, the drink is free: their stamps go back to0and it returnstrue. Otherwise they get one stamp and it returnsfalse.stamps_of(customer)returns the stamps ofcustomer(0for someone who never bought).count_free()returns how many free drinks the shop has given in total.get_top_customer()returns the customer who has bought the most drinks, free ones included. On a tie it returns the name that comes first alphabetically. Returns""if nobody has bought anything.
The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.
Example 1
StampCards(2)
buy("kim") returns false
buy("kim") returns false
buy("kim") returns true
buy("lee") returns false
stamps_of("kim") returns 0
buy("lee") returns false
count_free() returns 1
get_top_customer() returns "kim"
kim pays for two drinks, which earns two stamps, so the third drink is free and the stamps start over. In total kim has bought 3 drinks and lee 2.
Constraints
1 <= goal <= 4customerhas1to5lowercase 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.