8 The vending machine

In this capstone, you will

  • Implement functions and classes
  • Code using variables and values
  • Use if-else constructs

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 ...

Get Get Programming with Scala now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.