I am somewhat frustrated as this is the first Java assignment I am stuck on and cant seem to get moving on. This assignment builds on our previous assignment which scanned a text files' elements into an array. My code for that assignment works fine so I at least have a start. Now our assignment is to take those objects and somehow run them through the Collections Class and test their efficiency. I tried to create an array list but am confused on where in my code I should create it and which loop I should use to add to the collection object. Any suggestions?

Here is my assignment:
Specification
Using your WordFrequency1 and WordStore classes and create a new class called CollectionsTest.java that does the following:

1. Prompts the user for the name and path of the BNC word frequency file, reads the data from the file, puts the data in WordFrequency objects and stores the objects in an array called word[]. This is what the WordStore class did. You may reuse it, or cut and paste.

2. Declare three WordFrequency reference variables and set them to the following values from the WordFrequency array:

If you use your WordFrequency class, you will need to add a compareTo() method that sets the “Natural Ordering” of the class to ascending order by the frequency field. If you use my WordFrequency class, the compareTo() method is already provided. 2 We are storing the data in an array first so that we do not have to read the data from the file multiple times, but more importantly, so that the time required to read the data from the file will not be counted in the performance for each of the Collection classes. The file read time would be so large as to overwhelm any differences in the performance of the Collection classes, and would vary depending on other disk activity occurring on your system while the program is running.


begin -word[0]
middle- word[104327]
end- word[208655]


3. Using the word[] array, for each of the Collections classes (ArrayList, HashSet, LinkedList, TreeSet and Vector) do the following:
a. Create an object of the appropriate class using the default constructor.
b. Using a loop, take each WordFrequency object sequentially from your word[] array and add it to the Collection object using the add(Object o) method.
4. Now we will do some timing on the performance of add(). a. Declare three long variables, startTime, stopTime and
totalTime. b. Around each of the 5 loops created in step 3, place the following timing
code:
startTime = System.nanoTime(); // your add() loop goes here... stopTime = System.nanoTime(); totalTime = stopTime-startTime; System.out.println(totalTime);

5. Now we will do some timing on the performance of searching for data using
contains().
a. For each of the 5 Collection objects created in step 3, do four timing tests for contains() – contains(begin), contains(middle), contains(end) and contains(new WordFrequency(0, “”, “”, 0))3.
b. For each of the 20 tests above, use code similar to the timing code given in step 4, but replace the add()loop with the contains() test.

6. If you run your program multiple times, you will notice that the times vary (in some cases significantly4). Let’s average out the times to get a more accurate measurement. Around each of your timing tests, put a loop to repeat the test multiple times (try 100 or 1000). Print the average of total Time at the end.


Here is my code for the WordFrequency Class thus far:

public class WordFrequency implements Comparable<Object> {
String word;
String partOfSpeech;
int numberOfFiles;
int frequency;

/**
* Creates a WordFrequency object.
*/
public WordFrequency() {
this.word = null;
this.partOfSpeech = null;
this.numberOfFiles = 0;
this.frequency = 0;
}

/**
* Creates a WordFrequency object.
* @param frequency the frequency of the word
* @param word the word
* @param partOfSpeech the part of speech of the word
* @param numberOfFiles the number of files the word appears in
*/
public WordFrequency(int frequency, String word, String partOfSpeech, int numberOfFiles)
{
this.frequency = frequency;
this.word = word;
this.partOfSpeech = partOfSpeech;
this.numberOfFiles = numberOfFiles;
}

/**
* Returns the frequency of the word.
* @return the frequency of the word
*/
public int getFrequency() {
return frequency;
}

/**
* Sets the frequency of the word.
* @param frequency the frequency of the word.
*/
public void setFrequency(int frequency) {
this.frequency = frequency;
}

/**
* Returns the word itself.
* @return the word itself
*/
public String getWord() {
return word;
}

/**
* Sets the word.
* @param word the word itself
*/
public void setWord(String word) {
this.word = word;
}

/**
* Returns the part of speech of the word.
* @return the part of speech of the word
*/
public String getPartOfSpeech() {
return partOfSpeech;
}

/**
* Sets the part of speech of the word.
* @param partOfSpeech the part of speech of the word
*/
public void setPartOfSpeech(String partOfSpeech) {
this.partOfSpeech = partOfSpeech;
}

/**
* Returns the number of files that the word appears in.
* @return the number of files that the word appears in
*/
public int getNumberOfFiles() {
return numberOfFiles;
}

/**
* Sets the number of files that the word appears in.
* @param numberOfFiles the number of files that the word appears in
*/
public void setNumberOfFiles(int numberOfFiles) {
this.numberOfFiles = numberOfFiles;
}

/**
* Returns a String representing the word.
* @return a String representation of the word
*/
public String toString() {
return "WordFrequency [word=" + word + ", partOfSpeech=" + partOfSpeech
+ ", numberOfFiles=" + numberOfFiles + ", frequency="
+ frequency + "]";
}

/**
* Tests if another WordFrequency object is equal to this one.
* @return if the other WordFrequency object is equal to this one
*/
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
WordFrequency other = (WordFrequency) obj;
if (frequency != other.frequency)
return false;
if (numberOfFiles != other.numberOfFiles)
return false;
if (partOfSpeech == null) {
if (other.partOfSpeech != null)
return false;
} else if (!partOfSpeech.equals(other.partOfSpeech))
return false;
if (word == null) {
if (other.word != null)
return false;
} else if (!word.equals(other.word))
return false;
return true;
}

/**
* Compares this WordFrequency object to another.
* @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
*/
public int compareTo(Object o) {
return frequency - ((WordFrequency)o).frequency;
}

}


Here is my messy code for my CollectionsTest Class:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.*;
import java.util.List;
import java.util.Scanner;
import java.util.Vector;
import java.util.LinkedList;

import javax.swing.JFileChooser;

/**
* Reads a file of word frequency information and stores it in an array.
*
*This is the WordStore class from the last assignment
*/
public class CollectionsTest {








/**
* Reads a file of word frequency information and stores it in an array.
* @param args
*/


public static void main(String[] args) {
final int NUM_WORDS = 208656;

JFileChooser fileChooser = new JFileChooser();
File file;
WordFrequency[] word = new WordFrequency[NUM_WORDS];
int i = 0;




fileChooser.setDialogTitle("Open BNC Word Frequency file");
fileChooser.showOpenDialog(null);
file = fileChooser.getSelectedFile();


try {
Scanner in = new Scanner(file);

while (in.hasNext()) {
word[i] = new WordFrequency(in.nextInt(),
in.next(),
in.next(),
in.nextInt());

i++;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}

System.out.println(word[0]);
System.out.println(word[word.length-1]);
}

//These are the reference variables I was asked to create in the assignment. Im not even sure they are correct and I doubt they are in the right place, any suggestions ??
WordFrequency[] begin = new WordFrequency[0];
WordFrequency[] middle = new WordFrequency[104327];
WordFrequency[] end = new WordFrequency[208655];
ArrayList<WordFrequency[]> word1 = new ArrayList<WordFrequency[]>();


}