Practice · 1 of 3
The candy machine lifecycle
CHALLENGE
Difficulty: advanced+25 XP
Implement CandyMachine: constructor takes the starting candy count (coins start at 0). buy() dispenses one candy and takes one coin — returns false (changing nothing) when out of candy. restock(n) adds n candies, allowed at any time. emptyCoins() returns the collected coins and **resets the coin count to zero**.
Press Submit to check your solution.
Back to lesson: Practice: Class design gauntlet