Question: Implement a class FiniteStateMachine for DFA in JAVA. Your class should have following member fields: list of states, list of inputs or alphabet, transition table,

Implement a class FiniteStateMachine for DFA in JAVA.
Your class should have following member fields: list of states, list of inputs or alphabet, transition table, start state and final states.
First, Implement the following public member functions to run input string through your FSM:
boolean Execute(string s); // returns true if the string s is accepted by the FSM or false if it is rejected
int[] Path(string s); // returns an array of indices of the states the FSM runs through given the input string s.
Second, Write a set of unit tests to validate that your implementation is correct. Implement the driver code to read a specification of the FSM from file so you can build the FiniteStateMachine object. Then read a number of test strings from the same file and output whether each string is accepted or not.
The input file will be of the following format:
num // number of states, states are numbered from 0 to num -1
string // string will contain characters for the alphabet
num // number of transitions
num-from, char, num-to // one transition per line: num-from is the number/index of the state the transition starts from, char is the input, and the num-to is the number/index of the state the transition ends at
num // index of the start state
num1, num2, num3,...// list of numbers for the indices of final states
test-string // multiple lines of test strings, one on each line
Your output will be one line per each test-string from the input file: true for accepted test strings and false for rejected test strings.
Thrid, Once you have the code working for DFA, adapt it to support NFA. You need to add one additional member function to determine if the FSM is DFA or NFA:
bool IsDFA(); // returns true for DFA and false for NFA
Your submission should include support for both DFA and NFA.
To implement Execute for NFA, youll have to employ backtracking.
Fourth, implement a method that converts NFA to DFA:
void ToDFA(); // converts NFA to DFA, does nothing if FSM is already a DFA.
SCREENSHOT THE OUTPUT PLEASE!

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!