Simple Example of A Genuine Finite State Machine

A Simple Vending Machine

A vending machine dispenses pieces of candy that cost 20 cents each. The machine accepts nickels and dimes only and does not give change. As soon as the amount deposited equals or exceeds 20 cents, the machine releases a piece of candy. The next coin deposited starts the process over again. The operation of the machine is represented by the diagram above. Each circle represents a state of the machine: the state in which 0 cents has been deposited, 5 cents, 10 cents, 15 cents, and 20 cents or more. The unlabeled arrow pointing to "0 cents deposited" indicates that this is the initial state of the machine. The double circle around "20 cents or more deposited" indicates that candy is released when the machine has reached this state. (It is called an accepting state of the machine because when the machine is in this state it has accepted the input sequence of coins as payment for candy.) the arrows that link the states indicate what happens when a particular input is made to the machine in each of its various states. For instance, the arrow labeled "nickel" that goes from "0 cents deposited" to "5 cents deposited" indicates that when the machine is in the state "0 cents deposited" and a nickel is inserted, the machine goes to the state "5 cents deposited." The arrow labeled "dime" that goes from "15 cents deposited" to "20 cents or more deposited" indicates that when the machine is in the state "15 cents deposited" and a dime is inserted, the machine goes to the state "20 cents or more deposited" and candy is dispensed. (In this case the purchaser would pay 25 cents for the candy since the machine does not return change.) The arrow labeled "dime" that goes from "20 cents or more inserted" to "10 cents deposited" indicates that when the machine is the state "20 cents or more deposited" and a dime is inserted, the machine goes back to the state "10 cents deposited". (This corresponds to the fact that after the machine has dispensed a piece of candy, it starts the operation all over again)