CPSC 220 Fall 2004
Program 1: A Token Scanner

  1. Write a class Scanner with the following interface:

    The Scanner constructor opens the given file for reading text, and nextToken() returns the next token in the file. For our purposes a token is one of two things:

    So the text below contains the 12 tokens shown:

       public class       Test5
       //Very silly
    Tokens:  public
    Things to keep in mind:

  2. Write a class TestScanner that prompts for and reads in a filename, then creates a Scanner object and uses it to get the tokens in that file. You may use the methods of the Keyboard class to read if you like; remember to import cs1.Keyboard. As you get the tokens, list them to the standard output, one per line. At the end, print the total number of tokens found in the file.

    Be sure to test your program on a variety of input files, including (but not limited to) the following:

What to Turn In

Turn in hard copy of your Scanner.java and TestScanner.java classes. Also tar your directory and e-mail it to bloss@roanoke.edu with cpsc220 prog1 in the subject line.