Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in python please Assignment 7 A: Finite State Automata. In computer architecture ( a class you might take in the future ) we teach a

in python please
Assignment 7 A: Finite State Automata.
In computer architecture (a class you might take in the future) we teach a concept called Finite
State Automata. Also known as State Machines, these models show different states of a
system and how you can move from one to other. We are going to simulate one using objects.
First, review the following diagram:
You will create a FSA class with one attribute: int state. The valid states are shown in the
diagram above. It should also have the following methods:
constructor: Takes in one integer for the state attribute. If the state is not one of the values
shown, it should be initialized to 0 and the constructor should print out This is an invalid
state. Starting at state 0
01
32
int goToNextState(): Takes in no parameters and advances the state variable to the next
state based on the diagram above. It should then return the state variable. It should not
print anything.
bool/Boolean end(): Takes in no parameters. It returns TRUE if the state is currently 3,
and returns FALSE otherwise.
You will then create a separate class (and file), Assignment7A. In its main method, you
should do the following:
Prompt the user to enter a state
Create a new FSA object using the constructor
Create a loop and prompt the user with two choices
Go to next state This should call the goToNextState() function on the FSA
object and print the current state based on the value returned from the
function
End This should call the end() function. If the returned value is TRUE, end
the loop and program. Otherwise, tell the user they can only end the program
at state 3.
Sample Output:
[Finite State Automata]
What state do you want to start at?1
What will you do?
>Go to next state
>End
Go to next state
Youre now at state 2.
What will you do?
>Go to next state
>End
END
You cant stop here; you can only stop at state 3.
What will you do?
>Go to next state
>End
Stop
[Invalid command!]
What will you do?
>Go to next state
>End
Go to NEXT state
Youre now at state 3.
What will you do?
>Go to next state
>End
End
The FSA has shut down.

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

Online Systems For Physicians And Medical Professionals How To Use And Access Databases

Authors: Harley Bjelland

1st Edition

1878487442, 9781878487445

More Books

Students also viewed these Databases questions