My program will read in a paragraph of words (stored in a text file). It will then need to do the following:
- Print out a list of all the words (alphabetical order). For each word, print the frequency count (how many times the word appears in the entire paragraph) and the line numbers in which the word appears on (does not need to be ordered). If a word appears on a line multiple times, the line number does not need to be stored twice (the frequency count of this word will still be updated)
- Display a list of words ordered from most frequent to least frequent.
- The user will input a specific word. If the word is found, print out its frequency count.
Limitations: I cannot use the Collections
class and I cannot store data multiple times. (e.g. Reading in words from the paragraph and storing them into a Set and an ArrayList)
Coding this won't be hard, but I can't figure out what would be the most efficient implementation since the data size could be a few paragraphs from a Wikipedia article or something. Here's my idea for now:
- Have a Word class. This Word class will contain methods to return the word's frequency count and the lines in which the word appears on (and other relevant data).
- The paragraph will be stored in a text file. The program will read the data line by line. Split the line into an array and read in words one by one.
- As words are being read in from the text file, put the words into some sort of structure. If the structure does not contain the word, create a new word object.
- If the structure already contains the word, update the frequency counter for that word.
- I will also have a
int
to record down the line number. These line numbers will be updated accordingly.
- I will also have a
This is somewhat incomplete, but it is what I'm thinking for now. The whole 'Word' class may probably be completely unnecessary, too.