Homework 3A: Unique words program.

Out: October 30, 2001
Due: November 8, 2001

Write a program that reads its input text, placing each word in a binary search tree, keeping a count of how many times each word has been placed in the tree. After the text is all read, write out the three, the words in alphabetical order, with the word's count next to each word.

Please use the input redirection operator in Windows and Unix to use the recommended test files as input. On both platforms, the less-than sign redirects a file into the input of a program. In this example, java will run UniqueWords.class and instead of typing input, the input will be from a file named test1:

> java UniqueWords < test1
blue (1)
fish (4)
one (1)
red (1)
two (1)
Where file test1 is:
one fish two fish
red fish blue fish

Hints:

Look at the InputIntegers class for help with the input and parsing of strings. That class not only reads strings, parses the strings into words, but then tries to convert each word to an integer. You just have to stop after parsing and return the parsed string.

Do not worry about punctuation, upper or lower case. It is fine if "word,", "word." and "word" are all different words (because of the punctuation glued onto the end of the words).