CS242: Advanced Programming Concepts in JAVA

Fall 2010

Program 6

Due: 2:00 PM, Monday, 10/18/10

This assignment is to implement a simple command line interface. That is, it allows the user to enter a series of commands to control execution of a program and shows the user the results of each command.

This program should still follow the structure of Program 5: it should have classes TestCheckers, Game, Checkers, Board, and BadRowOrColumnNumberException and interface Moves that satisfy the design requirements (class structure, methods, and packaging) specified in Program 5.

The program should have a class named TestCheckers which contains the main method. This time the main() method needs to manage only a single game. The main() method should accept commands from the command line, one command per line. Commands are of the form
command parameter1 parameter2 ....
All commands are free-format, i.e., variable spacing before and after commands and parameters, and not case-sensitive. That means the command can be typed in upper or lower case characters, or a mixture of both.

As each command is read, it is echoed to the screen. That is, it is printed on the screen exactly as it was entered. Then it is reprinted in a standard format described below.

The commands are:

  1. start
    A new game begins, with the pieces placed as they should be at the start of a game.
  2. remove row col
    row and col must be nonnegative integers. Removes the piece at (row,col)
  3. place piece row col
    piece, row, and col must be nonnegative integers. Puts a piece on (row,col). The parameter "piece" is an integer that indicates what kind of piece it is
  4. move fromrow fromcol torow tocol
    fromrow, fromcol, torow, and tocol must be nonnegative integers. Moves the piece from (fromrow,fromcol) to (torow,tocol).
  5. show row col
    row and col must be nonnegative integers. Prints the contents of (row,col) to the screen.
  6. display
    Displays the board on the screen.
  7. quit
    The program terminates.
The program should prompt the user for a command. You can decide how to do this. After the user enters a command, the program will echo it to the screen, and then check that it was a valid command. If it isn't, then an error message is displayed. If it is, then the command is printed out again, but using the following formatting:
After this, the program should repeat the entire process, until a quit command is entered. After processing the quit command, the program terminates. Here is an example. The ">" is the prompt to the user.
>         start
         start
START
>  Move 5  1     7 4
  move 5  1     7 4
MOVE         5   1   7    4
>  moove 34 14
  moove 34 14
Illegal command
>   placE  4  2  6
   placE  4  2  6
PLACE        4   2   6
>  place  5   -8  2
  place  5   -8  2
Illegal parameter: -8
>quit
quit
QUIT
It is not necessary to use additional exception handling in this program, but you may want to. All exceptions should be detected and thrown in the method where they occur, and caught in main(). This will include I/O exceptions and exceptions caused by bad parameter values. You don't need to consider illegal checkers moves (unless you want to). All exception classes that you define should contain variables and methods that enable main() to extract important information about the exception, so that main() can respond appropriately to each exception.

Your grade will be based on how well you design and implement the code, how thorough your error handling is, on good programming practices, and on thorough testing. Coding guidelines for Java programs are posted here.

Add comment documentation to your program and use javadoc to extract the documentation into an HTML file. Include a javadoc comment for each class and each method. The class comment should include your name and the date (use the @author tag). Method comments should briefly describe the purpose of the method, its arguments, and what, if anything, it returns (using @param and @return as appropriate).

The physical location of the javadoc comments is critical. A class comment must immediately precede the line containing the keyword class, and method comments must immediately precede the method.

When you have commented your source files, run javadoc to create the .html files and view them in a browser of your choice.


What to submit:
Your grade on the program will be based on: