Description
CST8130: Data Structures — Assign #4- Dictionary
Using TreeMap Generic Data Structure
Problem Description:
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.
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, CST8130 – Data Structures
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:
• 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.
Assign4: Dictionary
Reviews
There are no reviews yet.