Lesson 8 Capstone 1: Let’s build a vending machine!
In this lesson, you will:
- Implement functions and classes
- Code using variables and values
- Use if…else statements
In this capstone, you’ll implement a vending machine. Your vending machine sells two products: a white chocolate bar for $1.50 and a granola one for $1.00. Let’s keep things simple and assume that your appliance doesn’t give any change back.
A customer can buy one item at the time by selecting a specific product and inserting money into the vending machine. Once the vending machine receives the request, then it should check that the product is available and the given money is enough: if all the checks are successful, then it should collect the money and release the product.
Let’s analyze the business requirements and identify the main components of your vending machine.
8.1 The Vending Machine
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 message explaining what went wrong. When successful, it should collect the money and release the product together with a message that acknowledges the purchase.