// Lab 2, CS 335J, Winter 2008 – Barbara Wahl // Alphabet Class, part 2 // Add the methods “getLanguage(int n)” and “printLanguage()” to Alphabet class, // and writing a main method to test. public Vector getLanguage(int n) // pre: n >= 0 // post: returns a Vector containing language S* (in lexicographic // order) // up through length n; language strings are stored in the Vector as // StringBuffer objects. { Vector v = new Vector(); v.add(new StringBuffer("")); // first is the empty string int finger = 0; // pointer for generating more strings StringBuffer oldString = (StringBuffer) v.get(finger); StringBuffer newString; while(oldString.length() < n) { // use oldString to generate more strings in language for(???) // for each symbol in the alphabet… { // start with oldString: newString = new StringBuffer(oldString.toString()); ??? // append ith alphabet symbol to end of newString ??? // add a StringBuffer copy of newString to v } ??? // advance finger ??? // update oldString reference } ??? // return } public static void printLanguage(Vector v) // pre: v is a Vector of StringBuffer objects, where the first object // is the empty string, “” // post: v is pretty-printed, one string per line, from head to tail // note: instead of blank, print “epsilon” for the empty string ??? // ** TEST METHOD ** public static void main(String[] args) { // create two different alphabets, A1 and A2 ??? // call getLanguage on A1 & display using printLanguage ??? // call getLanguage on A2 & display using printLanguage } }