How would I appropriately store the data in an object array array that has two data members: String fruit and int frequency, with fruit being the type of fruit and frequency being the number of times each fruit appears in the array? (in this array, each fruit will only be listed once)
(word number, frequency, and word are separate columns. tabbing doesn't seem to work in this forum too well)
So far I have the input file broken up and put into an array called "library", and I've created a Word class with data members String word and int frequency (with the appropriate accessors) . I'm just not too sure how to count the frequency of each word, or identify each word in library as unique.
if you have to store this in an array, about the only thing you can do is this:
read a word
search the array to see if the word is already there
if it is, increment the counter
if not, add it with a counter of '1'
I'm not sure what 'word number' refers to...is it the position of the word in the original string? how do you store that after the 1st one? in other words (ha ha), if your string is "fred is fred", what would your final array look like?
1 fred 2
2 is 1
1 fred 1
2 is 1
3 fred 2
or something else?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
posted 10 years ago
the word number is just a counter of each unique word. it just increments by 1 every time there's another unique word, there's no particular order. The two values that matter are the name of the unique word and the number of times it appears in the library.