In this code challenge, you are given an implementation of the VendingMachine class that simulates a vending machine with a display and two buttons, left and right. When the machine starts, it displays the product menu where the user may select a product they wish to buy. The user may cycle through the products by pressing the right button and select a product by pressing the left button. After the product is selected, the machine displays another menu where the user may select how many items of the selected product they want.
In the second menu, the user may cycle through the possible numbers, from 0 to 4, by pressing the right button, and select the desired number of items by pressing the left button. The initial quantity is 1. Each time the user presses the right button, the selected quantity is increased by 1 and displayed.
The provided template uses the State pattern, and your task is to write the two methods of MenuQuantity class to satisfy the following logic:
If the selected quantity is 0, the program must print Cancelled and return to the first menu. If any other quantity is selected, the program must print Dispensing %quantity% packages of %product% where %quantity% is the selected quantity and %product% is the selected product and return to the first menu.
See the examples to get a better idea of how the simulation works.