Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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 addnickelint currentbalance
int newbalance;
ifcurrentbalance
newbalance;
ifcurrentbalance
newbalance;
ifcurrentbalance
newbalance;
ifcurrentbalance
newbalance;
ifcurrentbalance
deliver candy;
newbalance;
machine resets;
return newbalance;
In this example you can see that all of the 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started