In this capstone, you’ll implement a class, load it into the REPL, and interact with it. In particular, you’ll represent a vending machine that sells two products: a white chocolate bar for $1.50 and a granola bar for $1.00. Let’s keep things simple and assume that your appliance doesn’t give any change back.
A customer can buy an item by selecting a specific product and inserting money into the vending machine. Once the vending machine receives the request, it should check that the product is available and the given money is enough; if all the checks are successful, it should collect the money and release the product.
Figure 8.1 summarizes the execution flow of the interaction between a customer and the vending machine. A customer requests a product to buy. Following this operation, the vending machine should check if the product is in stock and if the money is enough to cover its cost. When rejecting the request, it should display a human-readable text explaining what went wrong. When successful, it should collect the money and release the product and a message that acknowledges the purchase.