/** * LinearSearchDictionary.java * Jeff Ondich, Carleton College, 2014-01-01 * * An implementation of the WordGameDictionary interface using a sorted list. * * This implementation is part of an introduction to Java interfaces in * Carleton's CS 201 Data Structures course. * * NOTE: I use the "this." notation in this sample since you're moving * from Python (which has "self.") to Java. In fact, I actually use * "this." routinely in my own Java code, but that makes me quite * weird. The vast majority of Java programmers omit "this.". */ import java.util.ArrayList; public class LinearSearchDictionary implements WordGameDictionary { private ArrayList wordList; public LinearSearchDictionary() { this.wordList = new ArrayList(); } public void addWord(String word) { this.wordList.add(word.toLowerCase()); } public boolean hasWord(String word) { word = word.toLowerCase(); if (word.length() == 1) { return true; } for (String wordFromDictionary : this.wordList) { if (word.equals(wordFromDictionary)) { return true; } } return false; } }