Ok, so we are supposed to write a program using the given SpellChecker class that checks to see if a given word is in a certain dictionary (which has been provided via text file). I'm still new to Java so I'm not really sure how to proceed. We are told to start with completing the checkWord method. I'm not even sure what to write. After that, we write an ArrayList and HashList class that extend SpellChecker and accept arrayList(s) and create a collection to save in a dictionary (not sure how to do this either).
import java.io.File; import java.util.Scanner; import java.util.ArrayList; import java.util.Collection; /** * Abstract base class for different types of spell checkers. Each different * spell checker should provide their own constructor that accepts an ArrayList * of correctly spelled words to use as a dictionary. * */ public abstract class SpellCheck { /** * will be a reference to the concrete spell checker's data structure * containing correctly spelled words */ Collection dictionary; /** * @param word * @return <code>true</code> if <code>word</code> or any words derived from * <code>word</code> is in this SpellChecker's dictionary; otherwise returns * <code>false</code> */ public boolean checkWord(String word) { //TODO: complete method return false; } /** * Generates an ArrayList of possible "root" words from an original word * that can also be used to search the dictionary. For example, if the * original word is "Puppies" the alternateWords method will return * [puppies, puppy, puppi, puppie] * * <br><br> * * Hint: Only call alternateWords if the word passed to checkWord was not * found in the list of correctly spelled words. * * @param originalWord * @return an ArrayList of words derived from the originalWord * */ private ArrayList<String> alternateWords(String originalWord) { ArrayList<String> alternates = new ArrayList<String>(); int length = originalWord.length(); String ending; // convert the original word to lower case originalWord = originalWord.toLowerCase(); alternates.add(originalWord); if (length > 3) { ending = originalWord.substring(length - 3, length); // if the word ends with -ing // remove the -ing // remove the -ing and add -e if (ending.equals("ing")) { alternates.add(originalWord.substring(0, length - 3)); alternates.add(originalWord.substring(0, length - 3) + "e"); } // if the word ends with -ies // remove the -ies and add -y if (ending.equals("ies")) { alternates.add(originalWord.substring(0, length - 3) + "y"); } } if (length > 2) { ending = originalWord.substring(length - 2, length); // if the word ends with -es // remove the -es // remove the -s if (ending.equals("es")) { alternates.add(originalWord.substring(0, length - 2)); alternates.add(originalWord.substring(0, length - 1)); } // if the word ends with -ed // remove the -ed // remove the -d if (ending.equals("ed")) { alternates.add(originalWord.substring(0, length - 2)); alternates.add(originalWord.substring(0, length - 1)); } // if the word ends with -ly // remove the -ly if (ending.equals("ly")) { alternates.add(originalWord.substring(0, length - 2)); } } if (length > 1) { ending = originalWord.substring(length - 1, length); // if the word ends with -s // remove the -s if (ending.equals("s")) { alternates.add(originalWord.substring(0, length - 1)); } } return alternates; } }