CS 110: Introduction
to Computing with Java
Do a Google search on the three word
phrase Word Frequency Analysis. Study
the topic and its applications.
This lab has you finish a utility that counts
words in a text file. Word frequency analysis
is used by linguists and cryptographers in various applications.
We use the following algorithm. We maintain a Map of words and their frequencies in the
analyzed text. A Map is a table that
connects a key to a
lab gives you some experience working with the File I/O, exceptions, and Java
Copy the project. A nearly complete set of Java files for the
word count application can be found in Lab9.zip. Extract these files to folder of your
choosing on the student drive. As usual,
open Dr Java, create a new project, and open the files you just unzipped.
Go to the
DrJava Edit-> Preferences-> Compiler Options Menu and uncheck the box labeled
“Show Unchecked Warnings”.
Look at the code. You can make the code work by completing one
(or maybe 2) line of code in the WordCount
class. This line of code must create a Scanner object from a String containing
the file name. NOTE: You invoke this program on the Dr Java
Interactions Pane with two command line arguments: one for the file name and
one for the minimum frequency count.
Write the line of code and run the application. We have provided
three text files that you can use as sample data. These sample files contain the Declaration of
Independence (doi.txt), Homer’s Odyssey (odyssey.txt), and Dicken’s Great
Expectations (ge.txt). Use the
application to find the words that occur more than 100 times in the
Odyssey. Compare with the sample output
Test exceptional conditions.
what happens when you give an in
Modify the application.
modify the code so the case where an
Test your changes.
should see the following when you run the WordCount
class with application parameters “odyssey.txt” and “1000”:
> java WordCount odyssey.txt 1000
you leave, have your TA check off that you completed the lab. Make sure each person saves a copy of your
a document describing your experiences.
Your lab must be printed (not handwritten).
the following questions related to what you did in this week’s lab. You may complete the code on your own, but
the TA must certify that most of your work was done in the lab.
Answer each of the following
questions about the application:
In the original application, what
were the different ways that NumberFormatException
and IOException are handled?
all Java Collection objects used in this application. What are the roles of each object?
Describe what you learned doing this
lab. Explain what was difficult and what
Attach a listing of your completed WordCount
Note: You should work alone on writing the lab
Note: The assignment is due
at the BEGINNING of your next lab. No
late assignments will be accepted.
Emailed assignments will not be accepted. If you are not going to be in lab on the due
date, you can turn the assignment ahead of time to the CS110 TA box in the CS