CS154
Chris Pollett
Feb. 10, 2020
Neither | Outside | Inside | Both | |
---|---|---|---|---|
Closed | Closed | Open | Closed | Closed |
Open | Closed | Open | Open | Open |
Which of the following is true?
public abstract class Automata { public Automata() { } public void setState(int state) { currentState = state; } public boolean processString(String w) { for(int i = 0; i < w.length(); i++) { currentState = delta(currentState, w.charAt(i)); } boolean accept = finalState(currentState); return accept; } public abstract int delta(int state, char c); public abstract boolean finalState(int state); int currentState; }
public class TestAutomata extends Automata { public TestAutomata() { } public int delta(int state, char c) { int outState = 1; switch(state) { case 1: if(c == '0') { outState = 1; } else { outState = 2; } break; case 2: if(c == '0') { outState = 3; } else { outState = 2; } break; case 3: outState = 2; break; } return outState; } public boolean finalState(int state) { return (state == 2) ? true : false; } public static void main(String args[]) { TestAutomata test = new TestAutomata(); test.setState(1); if(args.length == 0 ){ System.out.println("It is not recognized by this automata."); } System.out.println("Checking the string "+ args[0]); if(test.processString(args[0])) { System.out.println("It is recognized by this automata."); } else { System.out.println("It is not recognized by this automata."); } } }