finiteAutomata
Class DFAMenu

java.lang.Object
  extended by finiteAutomata.DFAMenu

public class DFAMenu
extends java.lang.Object

Menu and query methods for the DFA class.

Version:
Fall 2007
Author:
Barbara Wahl

Constructor Summary
DFAMenu()
           
 
Method Summary
protected static void changeTransitionDialog(DFA dfa)
          Changes one transition based on user input.
protected static int constructorMenu()
          Displays constructor menu options until user makes a valid choice.
static void main(java.lang.String[] args)
           
protected static boolean menuHandler(int choice, DFA dfa)
          Takes the appropriate action based on constructorMenu options.
protected static int predefinedDialog()
          Prompts user to choose a pre-defined DFA and returns that choice (int code)
protected static void printLanguageDialog(DFA dfa)
          Reports language of the specified DFA up through user-specified max length.
protected static boolean pumpTest(DFA dfa, java.lang.String inString)
          Prints header for pump report and tests the pumping preconditions.
protected static void queryAlphabet(DFA dfa)
          Initializes alpha according to user input.
protected static void queryFinal(DFA dfa)
          Initializes isFinal array according to user input.
protected static void queryLabels(DFA dfa)
          Obtains and initializes state labels based on user input.
protected static int queryNumStates()
          Prints constructor menu banner and asks user how many states in DFA.
protected static boolean queryPredefined()
          Asks user if they want to use a pre-defined DFA.
protected static int queryStart(DFA dfa)
          Asks user for start state.
protected static void queryTransition(DFA dfa)
          For each state and each alphabet symbol, asks user for destination.
protected static int queryValidState(DFA dfa)
          Queries user repeatedly to enter a state label.
protected static int queryValidSymbol(DFA dfa)
          Queries user repeatedly to enter an input symbol.
protected static int queryValidTransition(DFA dfa, int i, int j)
          Queries user repeatedly to enter a valid destination state.
protected static void testEpsilonDialog(DFA dfa)
          Tests whether the epsilon string is accepted.
protected static void testingHandler(DFA dfa)
          Allows the user to repeatedly test strings or print the specified DFA's language.
protected static int testingMenu()
          Presents testing menu options to user and obtains valid choice.
protected static void testStringDialog(DFA dfa)
          Queries user for string to test and reports back.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DFAMenu

public DFAMenu()
Method Detail

constructorMenu

protected static int constructorMenu()
Displays constructor menu options until user makes a valid choice.

Returns:
choice (int from 1 thru 8)

menuHandler

protected static boolean menuHandler(int choice,
                                     DFA dfa)
Takes the appropriate action based on constructorMenu options.

Parameters:
choice - user's desired action code
dfa - the DFA being operated on
Returns:
true iff user is done with menu
Precondition:
1 <= choice <= 8

testingHandler

protected static void testingHandler(DFA dfa)
Allows the user to repeatedly test strings or print the specified DFA's language.

Parameters:
dfa - the DFA being operated on
Postcondition:
each input string is echoed back to the console with a report of the string's length and whether or not it is accepted

testingMenu

protected static int testingMenu()
Presents testing menu options to user and obtains valid choice.

Returns:
choice (int from 1 thru 4)

testEpsilonDialog

protected static void testEpsilonDialog(DFA dfa)
Tests whether the epsilon string is accepted.

Parameters:
dfa - the DFA being operated on
Postcondition:
reports string length (0) and result

testStringDialog

protected static void testStringDialog(DFA dfa)
Queries user for string to test and reports back.

Parameters:
dfa - the DFA being operated on
Postcondition:
reports string length and result

printLanguageDialog

protected static void printLanguageDialog(DFA dfa)
Reports language of the specified DFA up through user-specified max length.

Parameters:
dfa - the DFA being operated on
Postcondition:
queries user for max string length; reports language of DFA up through that max length

queryNumStates

protected static int queryNumStates()
Prints constructor menu banner and asks user how many states in DFA.

Returns:
positive int obtained from user for numStates

queryLabels

protected static void queryLabels(DFA dfa)
Obtains and initializes state labels based on user input.

Parameters:
dfa - the DFA being operated on
Postcondition:
user is prompted to enter a label for each state; responses are stored in stateLabel vector

queryPredefined

protected static boolean queryPredefined()
Asks user if they want to use a pre-defined DFA.

Returns:
true iff user response begins with 'Y' or 'y'

queryStart

protected static int queryStart(DFA dfa)
Asks user for start state.

Parameters:
dfa - the DFA being operated on
Returns:
valid state number (int from 0 thru numStates - 1)

queryAlphabet

protected static void queryAlphabet(DFA dfa)
Initializes alpha according to user input.

Parameters:
dfa - the DFA being operated on
Postcondition:
input Alphabet is initialized

queryFinal

protected static void queryFinal(DFA dfa)
Initializes isFinal array according to user input.

Parameters:
dfa - the DFA being operated on
Postcondition:
final states are initialized as requested by user

queryValidState

protected static int queryValidState(DFA dfa)
Queries user repeatedly to enter a state label.

Parameters:
dfa - the DFA being operated on
Returns:
corresponding state number of the first valid state label obtained

queryValidSymbol

protected static int queryValidSymbol(DFA dfa)
Queries user repeatedly to enter an input symbol.

Parameters:
dfa - the DFA being operated on
Returns:
corresponding symbol number of the first valid symbol obtained

queryValidTransition

protected static int queryValidTransition(DFA dfa,
                                          int i,
                                          int j)
Queries user repeatedly to enter a valid destination state.

Parameters:
dfa - the DFA being operated on
i - current state number
j - index of input symbol being read (position in alpha)
Returns:
destination state number (int from 0 thru numStates - 1)
Precondition:
0 <= i < numStates and 0 <= j < alpha.size()

queryTransition

protected static void queryTransition(DFA dfa)
For each state and each alphabet symbol, asks user for destination.

Parameters:
dfa - the DFA being operated on
Postcondition:
transition array is filled with valid state numbers as given by user

changeTransitionDialog

protected static void changeTransitionDialog(DFA dfa)
Changes one transition based on user input.

Parameters:
dfa - the DFA being operated on
Postcondition:
transition array is altered in zero or one places, as requested by user

pumpTest

protected static boolean pumpTest(DFA dfa,
                                  java.lang.String inString)
Prints header for pump report and tests the pumping preconditions.

Parameters:
dfa - the DFA being operated on
inString - String to be pumped
Returns:
true iff inString.length() >= numStates and inString is accepted
Postcondition:
(1) prints header for "pump" report (2) reports error if inString.length() < numStates (3) reports error if inString is not accepted

predefinedDialog

protected static int predefinedDialog()
Prompts user to choose a pre-defined DFA and returns that choice (int code)

Returns:
user's choice of DFA, 1 thru 6

main

public static void main(java.lang.String[] args)