Computer Science 101b Lab 6a: Arrays and Textfiles
Due: October 19, 2000

Objectives and Overview: This lab continues your work with arrays and textfiles.

Part 1

Now that you have had some experience with textfiles, and have been introduced to arrays, you can put these elements to design a word-frequency counting program. Write a program that prompts the user for the name of a textfile, then processes the file in the following way. In a manner similar to that described in class for counting the frequency of some common words in a textfile, store all the distinct words in the textfile in one array and count the number of occurrences of each word in another array.  The output should inform the user of the number of distinct words in the file, and then provide a list of these words along with their frequency (the number of times each one appears in the textfile).

There is a program skeleton in the file WordCountsSkel.java in the CS101b (Majercik) folder. The main method is already written, as are all the other method headers. You "only" need to write the method bodies. Use the documentation as a guide to what you need to do to complete the methods. The documentation in the skeleton is also a good indication of what I expect when you document a program you've written from scratch. I strongly recommend that you use this skeleton; it was taken from a working program and, more importantly, exhibits the kind of modularization we will be looking for when grading these labs.

Part 2

Answer the following questions, either with pencil and paper, or by providing printouts of the output produced by your program.
  • How many distinct words are there in each of the textfiles (tiny, poem, and literacy)?

  • Give a complete listing for the word frequencies in the textfiles tiny and poem.

  • Lab 6 Deliverables

    By 4pm on the due date, turn in a printed listing of your completed program from Part 1 and your answers to the questions in Part 2.  Also, submit an electronic copy of your completed program from Part 1 as lab6yourname.java to the Drop Box in the CS101b (Majercik) folder.