For this assignment, you will design and implement a program (i.e., a collection of interacting Java classes) for indexing the words in a file and allowing the user to search that index. Your program should include a GUI that allows three user-initiated actions.
Your program should be case-insensitive. That is, words should be considered equivalent if they have the same sequence of characters, regardless of capitalization. When reading and processing words from the file, you will need to be careful to remove trailing punctuation. For example, if "equal." appears at the end of a sentence, it should be recognized as the word "equal" and processed accordingly. Similarly, "JOY!!!" should be recognized as "JOY" or "joy".
HINT: When processing the text file, you will need to be able to read from the file
one line at a time, and then break the line into individual words. This can be done
several ways in Java. The Scanner
class has a nextLine
that reads
an entire line of text. You could then
construct another Scanner
object associated with that string,
and read individual words from that string just as you read from the console or
from a file. A simpler way, however, is to use the split
method
of the String
class. The split
method takes a delimiter
as it argument, and returns an array of all substrings, separated by that delimiter.
The delimiter can be a simple string, e.g., " "
, or it can be
a regular expression, e.g., "\\s+"
which represents any sequence of
whitespace characters.
Thus, the statement:
would have the affect of splitting line
into individual words
(as delimited by whitespace).
You should strive to follow good design principles in creating your program. In particular, you should utilize cohesive and loosely couple classes, and a GUI front-end with minimal application-specific code inside it. Javadoc comments should be included in all classes.