Due: 2:00 PM, Monday, 10/11/10
This assignment builds on Program 4. Your system should follow the same structure as in Program 4, with some changes:
1.
The methods remove, place, and show in the Board
class should handle row and column numbers that are not valid array indices by
using try and catch blocks. The catch block in each method should catch an ArrayIndexOutOfBounds exception, and throw a new exception
called BadRowOrColumnNumberException. This exception
class has three private variables which you can call whatever you want, but
let's assume they are:
int badRow
int badCol
int size
Their values are the row and column numbers that caused the ArrayIndexOutOfBounds
exception, and the size of the 2-dimensional array in the Board object
respectively. The catch block in each of the methods remove, place, and show
calls the BadRowOrColumnNumberException constructor
to set the values of these three private variables, and throws the BadRowOrColumnNumberException object.
2. The methods in the Checkers class that call remove, place, or show in the Board class should throw a BadRowOrColumnNumberException.
3.
The main method in TestCheckers
should catch a BadRowOrColumnNumberException, and use
the public access methods of BadRowOrColumnNumberException
(see interface diagram below) to print out an error message that describes the
exception. For example, if show was called with row and column numbers 2 and 9
respectively, it would print this out (or something like it):
Bad row or column number:
(2,9)
Size of game board is 8 by 8.
followed by a stack trace. The program should then
continue execution.
4.
The Checkers class should have a third form of
constructor:
Checkers(String[]
occupied)
The parameter occupied
is a list of squares on the board, using the same format as in Programs 2 and
3. These are the initial occupied squares in the instance of Board that
is a member of the Checkers object created by the constructor.
5. The main method in TestCheckers should begin by prompting the user for a list of squares. The user will then type this list on the keyboard. This time, it’s not a command line argument as in program 2, but stream input from the keyboard. The program should use this list to create a Checkers object and then test the various methods and error handling capabilities of the classes Checkers and Board. There are other errors to consider besides BadRowOrColumnNumberException, but in all cases, the program should note the error and continue execution. It’s up to you if you want to handle these other errors by using Exceptions or by testing for them directly in your code.
Class
BadRowOrColumnNumberException contains the three
private member variables described above and their access methods.
|
BadRowOrColumnNumberException |
|
BadRowOrColumnNumberException() |
|
int getBadRow() |
|
Int getBadCol() |
|
int getSize() |
The constructor sets the message variable inherited from the Exception class to the string “Bad row or column number: or something like that, and sets the three private variables as described above.
The other three methods are access methods for the private variables.
Add comment documentation to your program (all six 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:
o Turn in a hardcopy printout of your java source files TestCheckers.java, Game.java, Board.java, Checkers.java, Moves.java, and BadRowOrColumnNumberException.java, and a printout of your test run. Do not give me a copy of the javadoc.html files.
o All Java programs will be submitted by copying (or ftping) them to a specially designated directory in AFS. Each person in the class has a subdirectory which has the same name as your login in
/afs/cu/class/cs242/fa10
Within this individual directory, create a subdirectory named p5. Copy only the source files into this directory, not class files or javadoc files. So, for example, if your login name was smithjd then the six files TestCheckers.java, Game.java, Board.java, Checkers.java, Moves.java, and BadRowOrColumnNumberException.java should be copied to /afs/cu/class/cs242/fa10/smithjd/p5. These directories have permissions set so that no one other than yourself and Prof. Lynch can read the files. You may, of course, use whatever operating system and compiler you wish to develop your code, but the version you turn in, both hardcopy and the files submitted to AFS, must compile and run under JDK installed in the Clarkson ITL (our lab room). In particular, it should run with your files packaged according to the specifications in this assignment: Game.java, Board.java, Checkers.java, Moves.java, and BadRowOrColumnNumberException.java in a folder named games, and TestCheckers.java in some other folder.
Your grade on the program will be based on:
o Correct execution. The program must follow all the specifications above. The hardcopy of your program's execution should clearly demonstrate that it does. You may want to turn in hardcopy of more than one execution.
o Correct implementation. The program must follow all the design requirements above, in particular the interfaces of the classes and their access attributes, and the packaging.
o Error checking. In addition to BadRowOrColumnNumberException, you have to figure out what kinds of errors your program should check for, and how it should handle them. The hardcopy of your execution should include examples of these error handling capabilities.
o Readability of the code: commented and well-structured, so that it is clear what the code is doing. Use an accepted programming style. The style of the text is fine, or you can follow the Code Conventions. Whatever you do, be consistent.
o Appearance of the output. At this point, we haven't covered any of the ways to generate really nice looking output, but the display method should produce a picture of the board with all the rows and columns lined up nicely, and any error messages should be well-formatted and easy to read.
o Timely submission of your program. All hardcopy must be turned in by the deadline. Late programs will not be accepted. Printouts submitted electronically will be ignored.