CS242: Advanced Programming Concepts in JAVA

Fall 2008

Program 8

Due: 10:00 A.M., Monday, 11/03/08

For this assignment, you are to augment Program 7 so that it implements some file I/O commands.

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

As in Program 7, the main() should accept commands from the command line, one command per line. The commands that need to be modified or added are:

  1. start
    There are three cases:
    (1) No game is in progress. In this case, a new game begins, with the pieces placed as they should be at the start of a game.
    (2) A game is already in progress, but it has not yet been saved to a file.
    The user is asked if the game should be saved.
    If the user responds yes, then the user is prompted for a filename.
    If the filename already exists, then the user is asked whether the file should be overwritten. If the user responds yes then the game is written to that file.
    If the file does not exist, then it is created and the game is written to that file.
    Then a new game begins, with the pieces placed as they should be at the start of a game.
    (3) A game is already in progress, and it has previously been saved to a file, either during this run of the program or some previous run.
    The user is asked if the game should be saved. If the user responds yes then the game is written to that file.
    Then a new game begins, with the pieces placed as they should be at the start of a game.
  2. resume [filename]
    Three cases:
    (1) No game is in progress. Then the game that was saved in [filename] is read in, and it is resumed. (If no filename was specified, then the user is prompted for it.)
    (2) A game is already in progress, but it has not yet been saved to a file.
    The user is asked if the game should be saved.
    If the user responds yes, then the user is prompted for a filename.
    If the filename already exists, then the user is asked whether the file should be overwritten. If the user responds yes then the game is written to that file.
    If the file does not exist, then it is created and the game is written to that file.
    Then the game that was saved in [filename] is read in, and it is resumed. (If no filename was specified, then the user is prompted for it.)
    (3) A game is already in progress, and it has previously been saved to a file, either during this run of the program or some previous run.
    The user is asked if the game should be saved. If the user responds yes then the game is written to that file.
    Then the game that was saved in [filename] is read in, and it is resumed. (If no filename was specified, then the user is prompted for it.)
  3. save [filename]
    Three cases:
    (1) No game is in progress. This is an error.
    (2) A game is already in progress, but it has not yet been saved to a file.
    If [filename] is not specified, then the user is prompted for a filename.
    If [filename] does not exist, then it is created, and the game is written to that file.
    If [filename] already exists, then the user is asked whether the file should be overwritten. If the user responds yes, then the game is written to that file.
    (3) A game is already in progress and it has previously been saved to a file.
    If [filename] is not specified or it is the same as the file that the game is already saved in, then it is written back to the file.
    If [filename] is specified and it is different from the file that the game is already saved in, and [filename] does not exist, then it is created, and the game is written to that file.
    If [filename] is specified and it is different from the file that the game is already saved in, and [filename] exists then the user is asked whether the file should be overwritten. If the user responds yes then the game is written to that file.
  4. quit
    If no game is in progress, then the program terminates.
    If a game is in progress, then the user is asked whether the game should be saved. If the response is yes, then the game is saved as in the save command. Then the program terminates.
All game files should be kept in a folder named GameFiles, which should be in the current directory.

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

Add comment documentation to your program (all classes) 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: