// Lab 1, CS 335J, Winter 2008 – Barbara Wahl // Alphabet Class // An alphabet is a non-empty, finite set of "symbols" and can be used to generate // a “language” (a set of strings). If S is an alphabet, S* denotes the language // containing all strings of length 0 or more made up from the symbols in alphabet S. // Since S* is infinite, it cannot be stored in its entirety on a computer, but in // our second lab we will add methods to generate and print all the strings in // S* up through a specified length n. import java.util.*; public class Alphabet { // ** DATA FIELDS ** protected StringBuffer alpha; // character symbols // ** CONSTRUCTORS ** public Alphabet(String inString) // fully-specified constructor // pre: inString is a non-empty string with no repeated characters // (characters should be listed in the desired lexicographic order) // post: creates an Alphabet object whose symbols are the characters in // inString { ??? // initialize data field "alpha" } public Alphabet() // no-arg constructor // post: creates alphabet {a, b} { ??? // use “this” to call the first constructor } // ** ACCESSOR METHODS ** public int getSize() // returns number of symbols in this alphabet ??? public String toString() // returns a String copy of alphabet symbols ??? public char charAt(int i) // post: returns i-th alphabet symbol (counting from position zero) // if i<0 (i too small), return first symbol // if i is too large, return last symbol ??? ??? ??? // ** OTHER METHODS ** public boolean indexArray(String inString, int[] array) // pre: array.length() >= inString.length() // post: if inString contains any characters not in the alphabet, // method returns "false"; otherwise it returns "true" and // for each 0 <= i < inString.length(), the ith char of inString // is converted to its position in the alphabet, and this integer // position is stored at array[i] { boolean flag = true; // set to false if find an illegal character int index; // for each character in inString ... for(int i=0; i