Create the state diagram for a soda dispenser machine. Model the system as a state machine. Then, write a program
Create the state diagram for a soda dispenser machine. Model the system as a state machine. Then, write a program that simulates the soda dispenser machine. The program will execute in a loop waiting for users to enter coins. The only acceptable values as input are .05, .10, and .25. Any other value will be rejected by the machine. The cost of a soda is $1 so the program must continue to accept values until $1 is reached, and at that point the soda is dispensed, and the system begins the process again. In the case where input goes above $1, the system must dispense the soda and return the difference to the user. The sample output for the success use case is provided below. An alternate use case that deals with an incorrect input is presented below. As seen, when the user enters the value of .35, the machine is able to detect it displays an error message, and resumes execution of the state machine. This use case also shows the correct way of dealing with users inserting values higher than $1; in this case, the machine dispenses the soda and returns the excess value to the user.

9 years ago
Purchase the answer to view it

- main.zip