Question: A finite state machine is a device or model application where the device or model is in one of several discrete states at any given

A finite state machine is a device or model application where the device or model is in one of several discrete states at any given time and based on the current state it can transition to a limited number of subsequent states.
For instance, a traffic light can be in one of three states: red, yellow, or green. If it is in the green state it can only transition to the yellow state. In the yellow state it can only transition to the red state and so on. It is never red and yellow at the same time nor do the colors occur at random.
Below is a model of a finite state machine: a candy machine. Based on its current state there has been 10 cents deposited only a few discrete states can occur afterward:
More money can be deposited.
Candy can be delivered.
Candy can be delivered with change.
Your task for this lab is to describe transitions in a traditional function style, if not functions designed using the syntax of a popular language. For this exercise you may ignore the process of delivering change after candy is dispensed, and you need not worry about returning money before candy is dispensed (eg. a coin return button).
Here is an example to start you off:
This is C language syntax:
int addnickel(int currentbalance){
int newbalance;
if(currentbalance ==0)
newbalance=5;
if(currentbalance ==5)
newbalance=10;
if(currentbalance ==10)
newbalance=15;
if(currentbalance ==15)
newbalance=20;
if(currentbalance ==20){
deliver candy;
newbalance=0;
//machine resets;
}
return newbalance;
In this example you can see that all of the 5 states beyond start involving a nickel are represented.
Design your functions below and return the completed document in the space provided in uLearn.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!