Lab Exercise #8
for labs meeting Friday, Mar. 7, 2003
Objectives: The purpose of this lab is to experiment with the Java
StringTokenizer
class. We will use this later in a project.
Copy and examine programs53/CountWords.java. If you have your
Lewis/Loftus book with you, this is explained on p. 169ff. Compile and
run this program, entering various sentences.
Using your web browser, visit the Sun API site (which is linked from the
course web page) and look up the methods in java.util.StringTokenizer.
Note that these methods provide a set of active-iteration controls for
reading tokens from a string one at a time.
Now modify CountWords so that NextToken treats the set
of English punctuation characters as tokens and counts the punctuation
characters (but not bkanks) separately from the words. Recompile and rerun
the program and test this out.