Please see my comment to the question: some important declarations are missing.
However, I think I can see at least one more or less apparent bug, which is apparent even without knowing the detail of
wordTable
implementation. The bug is in this line:
wordTable.add(nextWord, new Integer(wordFrequency));
Most likely, this method adds a new object to
wordTable
. Instead, this object should have a way to retrieve existing object and increment it's integer member. Furthermore, if this is the case and if your code does not throw an exception, the
wordTable
object does not support uniqueness by the key, where the key should be the word (string).
Correct implementation can be based, for example on
java.util.HashMap<String, Frequency>
:
http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html[
^],
see also:
http://en.wikipedia.org/wiki/Hash_map[
^].
In this declaration, the type
Frequency
is some class with integer frequency member. The class is needed to have a reference-type object for the hash map value, so you could update it when needed.
It allows to search the object by key (String, in your case) with the
computational time complexity of O(1).
(Please see
http://en.wikipedia.org/wiki/Big_O_notation[
^].)
When you got a new word from
fileScanner
, you should get the
Frequency
object from the hash map. If the value is no found, add a new object with the frequency of 1. If it is found, increment its value by 1. At the end, you will have the dictionary of words with respective frequencies.
—SA