Strings containing aac, abcc, or bcb

Program 1 - Strings containing aac, abcc, or bcb

Due Date: Friday, September 15, 2017, 11:55pm

Write a program that recognizes strings over the alphabet {a,b,c} that contain either the substring aac, abcc, or bcb.

Your program is supposed to act like a finite state machine, so it is restricted to the following rules:

  1. 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.

  2. As soon as your program detects the newline character that marks the end of one string, it must write either "Yes" or "No" 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 accept the next string.

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

  4. 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 "No".

  5. Your program will continue to accept strings until the user breaks into the program by typing "Ctrl c", so your outermost loop can be an infinite loop. Use something like "while (true)"

You will be given a handout in class that will help you design your program. When your program is finished use the following command to submit it on the student machine:

submit aam 2490/prog1 FiniteStateMachine.java
You may submit as many times as is necessary. Only the final submission will be graded.

Sample run:

Your string> bbbabcbb  
Yes

Your string>
No

Your string> aaabccc 
Yes

Your string> aac 
Yes

Your string> cabcabcab 
No

Your string> aabcc 
Yes

Your string> ^c