import java.util.*; public class WordChecker { private ArrayList wordList; public WordChecker(String[] words) { wordList = new ArrayList(); for (String word: words) wordList.add(word); } /** * Returns true if each element of wordList (except the first) contains the previous * element as a substring and returns false otherwise, as described in part (a) * Precondition: wordList contains at least two elements. * Postcondition: wordList is unchanged. */ public boolean isWordChain() { /* to be implemented in part (a) */ return false; // remove this to test your answer to part a } /** * Returns an ArrayList based on strings from wordList that start * with target, as described in part (b). Each element of the returned ArrayList has had * the initial occurrence of target removed. * Postconditions: wordList is unchanged. * Items appear in the returned list in the same order as they appear in wordList. */ public ArrayList createList(String target) { /* to be implemented in part (b) */ return null; // remove this to test your answer to part (b) } // There may be instance variables, constructors, and methods that are not shown. } public static void main(String[] args) { String[] trueExample = {"an", "band", "band", "abandon"}; String[] falseExample = {"to", "too", "stool","tools"}; WordChecker ex1 = new WordChecker(trueExample); WordChecker ex2 = new WordChecker(falseExample); System.out.println("part (a)"); System.out.println("Your ex1.isWordChain() returns " + ex1.isWordChain() + " " ); System.out.println("Your ex2.isWordChain() returns " + ex2.isWordChain() + " " ); System.out.println("part (b)"); String[] partb = {"catch", "bobcat", "catchacat", "cat", "at"}; WordChecker ex3 = new WordChecker(partb); System.out.println( ex3.toString() ); System.out.println("createList(\"cat\") returns "+ ex3.createList("cat") + " "); System.out.println("createList(\"catch\") returns "+ ex3.createList("catch") + " "); System.out.println("createList(\"dog\") returns "+ ex3.createList("dog") + " "); } public String toString() { return wordList.toString(); } }