-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionaryLL.java
More file actions
58 lines (48 loc) · 1.36 KB
/
DictionaryLL.java
File metadata and controls
58 lines (48 loc) · 1.36 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
package spelling;
import java.util.LinkedList;
/**
* A class that implements the Dictionary interface using a LinkedList
*
*/
public class DictionaryLL implements Dictionary
{
private LinkedList<String> dict;
// TODO: Add a constructor
public DictionaryLL() {
dict = new LinkedList<String>();
}
/** Add this word to the dictionary. Convert it to lowercase first
* for the assignment requirements.
* @param word The word to add
* @return true if the word was added to the dictionary
* (it wasn't already there). */
public boolean addWord(String word) {
// TODO: Implement this method
String wrd = word.toLowerCase();
if(!dict.contains(wrd)) {
dict.add(wrd);
return true;
}
return false;
}
/** Return the number of words in the dictionary */
public int size()
{
// TODO: Implement this method
return this.dict.size();
}
/** Is this a word according to this dictionary? */
public boolean isWord(String s) {
//TODO: Implement this method
for(String ll : this.dict) {
if(ll.equalsIgnoreCase(s)) {
return true;
}
//System.out.println("smallDict "+ll);
}
return false;
}
public LinkedList<String> getDict(){
return this.dict;
}
}