CIT 591 Assignment 6: Word Counter
Fall 2008, David Matuszek

Purposes of this assignment:

General idea of the assignment:

Read in a list of stop words, one per line. A stop word is an "unimportant" word, like "the" or "of," that doesn't help indicate what the text is all about.

Read in two files, one containing stop words, and one containing English text. Count how many times each word occurs in the second file. Provide methods to determine which are the most common words, and to determine how common particular words are.

Details

Since we have not yet discussed how to read and write files, I am providing the method
    public static ArrayList<String> loadFile(String message) throws IOException.
When called, loadFile() will ask the user for an input file (using the message as the title of a dialog), and will return an arrayList of Strings; each String in the arrayList will represent one line of the file. Copy this method into your project.

Here are the requirements:

You do not need a main method; all your testing can be done from JUnit.

Provided code:

// import java.io.*and java.util.ArrayList;

public static ArrayList<String> loadFile(String message) throws IOException {       
    BufferedReader reader = null;
    ArrayList lines = null;
    JFileChooser chooser = new JFileChooser();
    
    chooser.setDialogTitle(message);
    int result = chooser.showOpenDialog(null);
    if (result == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        if (file != null) {
            String fileName = file.getCanonicalPath();
            reader = new BufferedReader(new FileReader(fileName));
            lines = new ArrayList<String>();
            String line = reader.readLine();
            while (line != null) {
                lines.add(line);
                line = reader.readLine();
            }
        }
    }
    return lines;
} 

About ArrayList<String>:

An ArrayList<String> is like an array, except that it doesn't have a fixed size; it can be expanded as needed. Since you don't know how many words you are going to encounter, you need an ArrayList instead of an array.

The angle brackets are an odd syntax that we haven't yet talked about. Just think of the whole thing, ArrayList<String>, as meaning an ArrayList that contains Strings. Use it just like an ordinary class name. So you can say things like
    ArrayList<String> words = new ArrayList<String>();
and it will work fine.

You can create an ArrayList of any object type, for example, ArrayList<Integer>. You can't create an array list of a primitive type, for example, ArrayList<int>.

For planning what methods you will need, you can assume that you can do anything with an ArrayList<String> that you can do with String[] array, but you can also change its size by adding and removing things. You just don't get to use the special [] syntax; you have to use Object syntax.

ArrayLists are described in the Java API, in the java.util package.

Advice:

Due Date:

Thursday, October 23, before midnight. Submit to Blackboard one copy of your project directory, properly zipped. Both your names should be in Javadoc comments in the classes. In addition, whichever of you turns the program in, should put your partner's name in the comments field in Blackboard.