bwen
April 22nd, 2008, 12:29 AM
Hello,
I am needing to create a couple methods which link to an array list, I am given an input array list such as:
String[] array = {"Hello", "This", "This", "is", "is", "a", "is", "test", "test}
and the two methods I need to make are printWords() and topWords().
printWords() is suppose to list all the words and how many times they appear, so in used in conjunction with the above array list it should display:
Count - Words
1 ----- Hello
2 ----- This
3 ----- is
1 ----- a
2 ----- Test
It doesn't have to be in any particular order, and in topWords() I need the method to display the 2 or 3 (however many, does it make a difference how many it needs to display?) top showing words. So in this case it would be:
Count - Words
3 ----- is
2 ----- This
2 ----- Test
I know there is a better method using HashMap but the guidelines stipulate that I use an ArrayList, I have done it using a HashMap also but I'll post up the code for that later (I need help with that too)
Any help would be greatly appreciated, I'm not expecting anyone to write me any code but any help at all would be great, I'm an engineering student and just been hit in the face with some programming so I am in much need at the moment.
Many thanks,
Brendan
I am needing to create a couple methods which link to an array list, I am given an input array list such as:
String[] array = {"Hello", "This", "This", "is", "is", "a", "is", "test", "test}
and the two methods I need to make are printWords() and topWords().
printWords() is suppose to list all the words and how many times they appear, so in used in conjunction with the above array list it should display:
Count - Words
1 ----- Hello
2 ----- This
3 ----- is
1 ----- a
2 ----- Test
It doesn't have to be in any particular order, and in topWords() I need the method to display the 2 or 3 (however many, does it make a difference how many it needs to display?) top showing words. So in this case it would be:
Count - Words
3 ----- is
2 ----- This
2 ----- Test
I know there is a better method using HashMap but the guidelines stipulate that I use an ArrayList, I have done it using a HashMap also but I'll post up the code for that later (I need help with that too)
Any help would be greatly appreciated, I'm not expecting anyone to write me any code but any help at all would be great, I'm an engineering student and just been hit in the face with some programming so I am in much need at the moment.
Many thanks,
Brendan