Description
Using TreeMap Generic Data Structure
In this assignment, you will write a program which builds a
tree “dictionary” of words that were found in a piece of text
and keep track of how many occurances there were of each
of the words.
Basic Requirements:
1. You must have a menu in your main method
with the following options:
• Reset the tree to empty
• Read a string of text from the keyboard and
add to the dictionary (optional)
• Read text from a file add to the dictionary
• Search for a word and show how many
times it occurred in the text
• Display the number of nodes in the
dictionary
• exit
2. You must use the collection class TreeMap to
implement this assignment. A description of the
methods available in that class can be found in
the Java documentation. Efficient use of the
class will factor in the assignment marking.
3. Hint: you might consider putting all the
“words” that you read into either uppercase or
lowercase to make sure that the words “there”
and “There” count as the same. You might also
choose to remove non-alphabetic characters (I
did) using the String method
word.replaceAll(“^\\s”,””); which replaces
basically all non-characters with nothing.
4. I have given you a .txt file of the book Oliver
Twist called oliver.txt. I have used that in my
sample output. (Note you may get slightly
different numbers if your editing of the word is
different than mine – that is okay).
Sample Output:
Enter 1 to clear dictionary,
2 to add text from keyboard,
3 to add text from a file,
4 to search for a word count,
5 to display number of nodes,
6 to quit
3
Enter name of file to process:
c:\oliver.txt
Enter 1 to clear dictionary,
2 to add text from keyboard,
3 to add text from a file,
4 to search for a word count,
5 to display number of nodes,
6 to quit
4
Enter word to search for:
the
the occurs 9635 times
Enter 1 to clear dictionary,
2 to add text from keyboard,
3 to add text from a file,
4 to search for a word count,
5 to display number of nodes,
6 to quit
4
Enter word to search for:
oliver
oliver occurs 747 times
Enter 1 to clear dictionary,
2 to add text from keyboard,
3 to add text from a file,
4 to search for a word count,
5 to display number of nodes,
6 to quit
4
Enter word to search for:
twist
twist occurs 57 times
Enter 1 to clear dictionary,
2 to add text from keyboard,
3 to add text from a file,
4 to search for a word count,
5 to display number of nodes,
6 to quit
5
There are 11670 nodes
Submission:
You must submit to the assignment link in Blackboard by the
due date and time a zip file (named
LastnameFirstNameAssign4) containing:
• all source code – ie .java files (Note – I may
choose to re-compile your program….so all code
must be available to me) with
• Your test plan in either .docx or .xls format
Failure to provide any of the above will have an effect on
your grade for this assignment. Marking guide will be
published shortly.