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 Executestring s; returns true if the string s is accepted by the FSM or false if it is rejected
int Pathstring 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 to num
string string will contain characters for the alphabet
num number of transitions
numfrom, char, numto one transition per line: numfrom is the numberindex of the state the transition starts from, char is the input, and the numto is the numberindex of the state the transition ends at
num index of the start state
num num num list of numbers for the indices of final states
teststring multiple lines of test strings, one on each line
Your output will be one line per each teststring 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
