forked from mitchfry/SpellChecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionary.java
More file actions
64 lines (59 loc) · 1.56 KB
/
Dictionary.java
File metadata and controls
64 lines (59 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//===================================================================
/**
* @author Mitchel Fry
* @version 1.1
*/
public class Dictionary implements CompareCount {
// instance variables
//You will replace "TestList with YOUR container ADT
private TestList<String> dictWords;
private static final boolean DEBUG = true;
// ======================== Constructors =========================
/**
* The dictionary for a simple spell checking program
*/
public Dictionary() {
try {
//Again, replace TestList with YOUR container ADT
dictWords = new TestList<String>();
} catch (Exception e) {
System.err.println("Exception in creating Dictionary");
}
}
/**
* Accessor Method for lastCompareCount
*
* @return lastCompareCount
*/
@Override
public int getLastCompareCount() {
// Just a wrapper for the interface
return dictWords.getLastCompareCount( );
}
/**
* Adds a word to the dictionary container
*
* @param newWord The word to add to the dictionary
*/
public void addWord(String newWord) {
try {
dictWords.add((newWord));
if (DEBUG) {
System.err.println("Word added to dictionary: " + newWord);
}
} catch (Exception e) {
System.err.println("Exception in adding string to dictWords");
}
}
/**
* Checks to see if the word exists in the container
*
* @param sWord The word to check
* @return Returns a true/false if word was found
*/
public boolean checkWord(String sWord) {
// check for found or end of dictionary
boolean correct = dictWords.contains( sWord.toLowerCase());
return correct;
}
}