CPSC 220 Fall 2002
Write a class Scanner with the following interface:
Program 2, Part 1: An Input Scanner
The Scanner constructor opens the given file for reading text.
Method nextToken() returns the next token in the file. For our purposes
a token will be a single non-alphabetic and non-numeric character,
such as punctuation, or a string of contiguous alphabetic and numeric
characters up until whitespace or end of file is encountered. Keep
in mind that whitespace may include spaces, tabs, and end-of-lines, and
may be encountered at any place, and in any combination, in the file.
- Scanner(String filename) -- creates a scanner object that reads from
- String nextToken() -- returns the next token in the file.
Write a class TestScanner that prompts for and reads in a filename, then
lists the tokens in that file, one per line. At the end it should print
the total number of tokens found in the file. If
an IOException is encountered either in creating the scanner or in reading
a token, your program
should print an appropriate error message and terminate.
What to Turn In
Turn in hard copy of your Scanner.java and TestScanner.java
Also tar your directory and e-mail it to firstname.lastname@example.org
(NOT email@example.com). IMPORTANT: The subject should be
cpsc220 prog2 pt1.