Computer Science Canada Map/ArrayList Help |
Author: | blackhawk_prince [ Sat Mar 08, 2008 6:50 pm ] | ||||
Post subject: | Map/ArrayList Help | ||||
I have the following assignment form school: There are a number of historical pieces of writing where the author is not known with 100% certainty. One way to try to prove a particular author did or did not write a particular piece is to analyze the frequency that each word is used. Write a program that takes a filename as an argument and displays a list of all of the words used in the file and the percentage of the file that each word represents. This list must be sorted in descending percentages. My teacher told us to map the word onto a custom class that can be later sorted. So I wrote the following:
I keep getting an error on line 22:
How do i fix this? I alos attached the code too. |
Author: | HeavenAgain [ Sat Mar 08, 2008 9:29 pm ] |
Post subject: | RE:Map/ArrayList Help |
the sort method is a void method... and so you cannot pass that as a parameter for initial size of your arraylist and after you sort it, since its a reference, your "stuff" variable is automatically sorted, and so the "sorted" variable is not necessary |
Author: | wtd [ Sun Mar 09, 2008 2:13 am ] | ||||||
Post subject: | RE:Map/ArrayList Help | ||||||
There are a few things you could be doing better here, though not related to the error you received. You use generics earlier, so apply those to your code.
And instead of a void method called "out," let's override the toString method. Oh, and we'll give "add" a better name.
|
Author: | blackhawk_prince [ Mon Mar 10, 2008 10:28 am ] |
Post subject: | RE:Map/ArrayList Help |
Thanks alot, I got my code to work now. |