Click to See Complete Forum and Search --> : Need Desperate Help With Project!


jblight
April 23rd, 2008, 12:03 AM
Hello everyone, i am new here and have come in search for desperate help/assistance. I have recently been given the following project.

This project involves implementing two classes called WordCount1 and WordCount2 (for Exercises 1 and 2 respectively). Both classes may be created in the one project called WordCount. Both classes count the number of occurrences of each word or phrase from a given input array of Strings. Your classes should process the given input array to produce the information regarding the occurrence of each word (this will be done in storeWords() below). The following methods should be implemented in both classes:

1. storeWords(String[] array) which iterates through a given passed array storing unique words/phrases and the number of times they were found in the array. This method will be called from the test class outlined in Exercise 3.

2. printWords() which will print out all unique words and their number of occurrences. Words can be printed out in any order.

3. topFourWords() which will print out the four words that have the most number of occurrences. These words will be printed in descending order of occurrence.

Now the given array to be used is

private String[] array = {"ICT", "School", "2B", "pencil", "2B", "2B", "project", "quiz", "pencil", "2B", "quiz", "pencil", "quiz", "2B", "I", "programming", "student", "star", "apple", "queen", "such", "access", "JJJ", "student", "project", "star", "orange", "summer", "spring", "hello", "access", "pencil", "programming", "elbow", "apple", "quiz", "pear", "orange", "around the horn", "such is life", "access", "ICT", "winter", "summer"};

Exercise 1 – WordCount1
Implement WordCount1 by using a List (or array) to store each word and the number of occurrences.
Hint: Implement a Count class that stores a single word and its count. Instances of the Count class may then be stored by the List (or array).
____________________________________________________________
Exercise 2 – WordCount2
Implement WordCount2 by using a Map to store each word and the number of occurrences.
____________________________________________________________
Exercise 3 – TestWordCount
Implement a class TestWordCount which declares the exact String array given in the example above, and passes it as a parameter to the storeWords methods in the two WordCount classes. This class should call the storeWords method, passing the example array, then call the two print methods for the WordCount1 class. It should then do exactly the same for the WordCount2 class. Include printing indicating which output is for exercise 1 and 2.
While you may test with other input arrays, this class must be demonstrated and submitted with the example array given previously.

Now i understand that the array is declared in the TestWordCount class and then the method storeWords(String[] array) is meant to be called from each WordCount1 and WordCount2 which will sort through the array. I have no idea were to even begin!!! any help would be very very appreciated.

Londbrok
April 23rd, 2008, 02:06 AM
Do not be intimidated by the size of the whole project. You have specs of methods expected. Do them, one by one, do not trouble with how they work together, separate issue at a time. When all of them do what they are supposed to do, connect the dots and you are home free.

Post back if finding difficulty.

ProgramThis
April 23rd, 2008, 06:14 AM
That's some good advice from Londbrok. To add to that advice, in order to ensure that each method is doing only what it is supposed to you can write some simple tests that call those methods, one by one, and check against an expected response.

You can do that with simple checks (if statements) or, if you are ambitious, you could read up on JUnit testing. I would recomend at your level just to check with an if statement.


public void doSomething( int x) {
return x * 3;
}
public static void main (String args[]) {
int n = 2;
int temp = doSomething(n);
if(temp == 6) System.out.println("doSomething() passed");
}

Just a simlpe example of how to use simple if statements to test simple methods.