CS 5 – Winter 2005

Lab 6

2/7/2005

 

Chapter 4, Problem 19 (pg 158):

 

Write an application to simulate a vending machine.  The vending machine should be preloaded with different types of candy and a quantity for each.  Each candy needs a price and a code.  The code would be a combination of a letter and a number.  For simplicity, just allow the letters to be an A, B, C, D, or E.

 

The Vending machine must have a mechanism to accept money.  You can use a text box and a button to accept it, but you then would need to validate that each value is a valid denomination of currency.  A better way is to create a button each for a nickel, dime, quarter, and dollar.  As each button is clicked, add the appropriate amount to the total.  Also, create a Change Return button to return the money entered to the user.

 

Create a series of buttons to allow the entry of a digit from 1 to 3 and a letter from A to E so that the user can select a candy to purchase.  Since each purchase is signified by a combination of a letter and a number, as the buttons are clicked, display the choice being made.

 

Finally, add a button to make the purchase.  It should validate that you have entered enough money to make the purchase, that you have selected a valid choice for a candy, and that candy still has a quantity greater than 0.  The last step is to indicate how much money is returned as change.