CS242: Advanced Programming Concepts in JAVA

Fall 2008

Program 5

Due: 10:00 AM, Monday, 10/06/08

This assignment builds on Program 3. As before, this is individual effort (don't copy!). Your system should be organized as follows:

  1. A package named Games. In the package are these classes:
    1. Game. This is an abstract class that can be extended to create classes for specific games. The Game class and its methods should be public, but its variables (except for its instance of Board) should be private.
    2. Board. You should be able to use the Board class from the previous assignment with some changes. The Board class and its methods (except for equals) should be accessible only from the other classes in the package Games and any of its subclasses, but its variables should be private. The equals method should be accessible from anywhere. The main modifications that you have to make are to allow game pieces of different kinds, and to handle exceptions. For example, in checkers, pieces can be red or black, and they can be regular checkers pieces or kings, giving a total of four kinds of pieces. (You don't need to know what these mean to do this assignment.) Each kind of piece is identified by a unique code. Squares on the game board can be unoccupied or occupied by a single piece of some kind. Use the following codes to indicate the occupancy of a square:
      0: unoccupied
      1: red checker
      2: black checker
      3: red king
      4: black king
    3. Checkers, which must be a direct subclass of Game. The Checkers class and its methods should be public, but its variables should be private.
  2. A class named TestCheckers containing a main program that thoroughly tests the Checkers and Board classes, including catching exceptions thrown by Board methods. TestCheckers should not be in the package Games.

The classes Game, Board and Checkers must satisfy the interfaces given below; that is, you are not free to change the name, type, or behavior of the given methods.

Your grade will be based on how well you design and implement the code (including whether you followed the directions in 1.1., 1.2, 1.3, and 2. above), on good programming practices, and on thorough testing. Coding guidelines for Java programs are posted here.

Class Game describes objects that implement a game on an nXn game board.
Game
Game(int n)
Game(final Game agame)
abstract void remove(int row, int col)
abstract void place(int piece, int row, int col)
abstract int show(int row, int col)
boolean equals(Game agame)

Class Board describes objects that implement the game board.
Board
Board(int n)
Board(final Board oldboard)
void remove(int row, int col)
void place(int piece, int row, int col)
int show(int row, int col)
boolean equals(Board gameboard)

Class Checkers describes objects that implement a checkers game.
Checkers
Checkers()
Checkers(final Checkers game)
void remove(int row, int col)
void place(int piece, int row, int col)
int show(int row, int col)
void move(int fromrow, int fromcol, int torow, int tocol)
void display()
boolean equals(Checkers agame)

The main method in TestCheckers should catch exceptions thrown by methods in Board and Checkers, and it should create several instances of Checkers.

Add comment documentation to your program (all four 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:
Your grade on the program will be based on: