In this lab, 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 times each of the words occurred.
Basic Requirements:
- 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 (**optional)
- Search for a word and show how many times it occurred in the text
- Display the number of nodes in the dictionary
- Exit
** you must implement either from file or from keyboard bonus marks if you do both!!
- 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.
- Hint: you should put 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 should also remove non-alphabetic characters using the String method word.replaceAll(^\s,); which replaces basically all non-characters with nothing.
- I have given you a .txt file of the book Oliver Twist called oliver.txt. I have used that in my sample output.
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
Reviews
There are no reviews yet.