Question: Simulating a DFA: Application 1 - Strings containing cbaa, bab, or cca Write a program that recognizes strings over the alphabet {a,b,c} that contain any

Simulating a DFA: Application 1 - Strings containing cbaa, bab, or cca

Write a program that recognizes strings over the alphabet {a,b,c} that contain any of the substrings cbaa, bab, or cca. Your program is supposed to act like a finite state machine, so it is restricted to the following rules:

Read only one character at a time. Do not store the characters in an array or a string variable. Your program must keep track of what it has seen (and what it still needs to see in order to have a good substring) as it goes along because it can only read a character once. It will do this by changing states.

As soon as your program detects the newline character that marks the end of one string, it must write either "Accept" or "Reject" to the screen (depending on whether the string just read is or is not in the language), then skip a line, then print "Your string> " and start processing the next string.

If the user types a string that contains any character other than a or b or c, your program should answer "Reject" to that string.

If the user presses "Enter" without typing any letters, that entry is to be considered the empty string and so your program should respond with "Reject".

Your program will continue to process strings until the user breaks into the program by forcibly ending the infinite loop (typing "Ctrl c" on student2), so your outermost loop can be an infinite loop.

Please use the template below and edit the code. Thanks!

Simulating a DFA: Application 1 - Strings containing cbaa, bab, or ccaWrite a program that recognizes strings over the alphabet {a,b,c} that contain

A Java Program Simulating a Finite State Acceptor Example of a Java program simulating a finite state machine: 1. Label the states in your machine, starting at 0 . 2. Make a transition table for your machine. Add an extra trap state that will handle an input character that is not in your alphabet. Make a column in your table for characters outside the alphabet. (Below the trap state is state 5, and column 2 is for characters other than a, b). 3. See if you understand the program below. The method run() is simulating the machine. You can use the same program skeleton shown below for any finite state acceptor. What would need to change for a different machine? 1

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!