Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

model this system as a FSM. Vending Machine allows users to deposit coins and push a button to dispense product, or a button to cancel

model this system as a FSM.

Vending Machine allows users to deposit coins and push a button to dispense product, or a button to cancel and get all deposited money back. 2 separate places: the currentBin and the bank. When product is dispensed currentBin is transferred to bank. On cancel, currentBin is returned. Product is only dispensed if currentBin >= 50 cents.

Commands: d (dime), q (quarter), D(dispense),C(cancel)

image text in transcribed

INIT: Initial state, the machine is waiting for the first coin deposit.

WAIT_FOR_CMD: The machine has received at least 50 cents and is waiting for a command from the user.

DISPENSING: The machine is in the process of dispensing the product.

DISPENSED: The machine has dispensed the product or not, depending on whether the current bin had enough money.

CANCEL: The machine is returning the money to the user.

Actions

: deposit: The user deposits coins (dimes or quarters).

dispense: The user requests to dispense the product.

dispensed: The machine dispenses the product if there is enough money in the current bin, otherwise it stays in the WAIT_FOR_CMD state.

cancel: The user requests to cancel and get their money back.

Write a program (any language) that simulates the vending machine, based on your FSM. The entire content of the FSM, including that appropriate output, should be hard- coded as a table. The entire simulation should look almost exactly like the program below, and the table(s) should correspond to your FSM (if your original FSM wasnt appropriate, make a new one.

Main State = 0

While(true) //this is an ongoing system with no end.

Cmd = input from keyboard

Output out[state][cmd]

State = newstate[state][cmd]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Database Security Applications And Trends

Authors: Michael Gertz, Sushil Jajodia

1st Edition

1441943056, 978-1441943057

More Books

Students also viewed these Databases questions

Question

Writing a Strong Introduction

Answered: 1 week ago