-
Notifications
You must be signed in to change notification settings - Fork 0
/
Word.java
48 lines (37 loc) · 864 Bytes
/
Word.java
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
import java.util.*;
public class Word implements Comparable<Word>{
//String
private String theWord;
//List of files that contain this word
private ArrayList<String> fileList = new ArrayList<String>();
//Constructor
public Word(String n){
theWord = n;
}
//Setters
public void theWord(String x){
theWord = x;
}
public void addFile(String x){
fileList.add(x);
}
//Getters
public String getWord(){
return theWord;
}
public ArrayList<String> getFileList(){
return fileList;
}
//Method used for comparisons:
public int compareTo(Word other){
return theWord.compareTo(other.theWord);
}
//toString method
public String toString(){
String strFiles = "";
for(int i=0; i<fileList.size(); i++)
strFiles += fileList.get(i) + " ";
String result = "Files containing '" + theWord + "': " + strFiles;
return result;
}
}