Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 1 (5 points): draw the finite automaton to represent the vending machine operations. Here you can find some free tools for you to draw

  • Task 1 (5 points): draw the finite automaton to represent the vending machine operations. Here you can find some free tools for you to draw finite state machines: Link
  • Task 2 (5 points): in the above given example, we need to modify the "refunding" state transition such that it requires the refunded money to be removed in order to move to the "ready" state, so the modified transition is defined as such: refunding -> remove -> ready. You are required to modify the given Java program to implement the updated transition.
  • Task 3 (5 points): A turnstile, used to control access to subways and amusement park rides, is a gate with three rotating arms at waist height, one across the entryway. Initially the arms are locked, blocking the entry, preventing patrons from passing through. Depositing a coin or token in a slot on the turnstile unlocks the arms, allowing a single customer to push through. After the customer passes through, the arms are locked again until another coin is inserted. In this task, you are required to draw the finite automaton to represent the turnstile operations.

  • Task 4 (25 points): implement a finite state machine which handles the turnstile transitions. Your program should have testing code to show how it works. You may choose to use unit testing or just use a main method for the testing purpose.

sample code :

image text in transcribed

image text in transcribed

import java.util.*; public class VendingMachine { private enum state { Ready(true, "Deposit", "Quit"), Waiting(true, "Select", "Refund"), Dispensing(true,"Remove"), Refunding(false, "Refunding"), Exiting(false, "Quiting"); state(boolean exp, string... in) { inputs = Arrays.aslist(in); explicit = exp; } state nextstate(String input, state current) { if (inputs.contains(input)) { return map.getOrDefault(input, current); } return current; } final List inputs; final static Map map = new HashMap(); final boolean explicit; static { map.put("Deposit", state.Waiting); map.put("Quit", state. Exiting); map.put("select", State.Dispensing); map.put("Refund", State. Refunding); map.put("Remove", state. Ready); map.put("Refunding", state. Ready); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); State state state. Ready; while (state != State. Exiting) { System.out.println(state. inputs); if (state.explicit){ System.out.print(" "); state = state.nextstate(sc.nextLine().trim(), state); } else { state = state.nextstate(state. inputs.get(0), state); } } } } import java.util.*; public class VendingMachine { private enum state { Ready(true, "Deposit", "Quit"), Waiting(true, "Select", "Refund"), Dispensing(true,"Remove"), Refunding(false, "Refunding"), Exiting(false, "Quiting"); state(boolean exp, string... in) { inputs = Arrays.aslist(in); explicit = exp; } state nextstate(String input, state current) { if (inputs.contains(input)) { return map.getOrDefault(input, current); } return current; } final List inputs; final static Map map = new HashMap(); final boolean explicit; static { map.put("Deposit", state.Waiting); map.put("Quit", state. Exiting); map.put("select", State.Dispensing); map.put("Refund", State. Refunding); map.put("Remove", state. Ready); map.put("Refunding", state. Ready); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); State state state. Ready; while (state != State. Exiting) { System.out.println(state. inputs); if (state.explicit){ System.out.print(" "); state = state.nextstate(sc.nextLine().trim(), state); } else { state = state.nextstate(state. inputs.get(0), state); } } } }

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

Step: 3

blur-text-image

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

How Do I Use A Database Research Tools You Can Use

Authors: Laura La Bella

1st Edition

1622753763, 978-1622753765

More Books

Students also viewed these Databases questions

Question

a. How are members selected to join the team?

Answered: 1 week ago

Question

b. Will new members be welcomed?

Answered: 1 week ago

Question

c. Will leaders rotate periodically?

Answered: 1 week ago