Assignment 4, CS 46A
30 points
due October 1, 2003

This assignment and Assignment 5 deal with drawing patterns on the screen. Assignment 5 deals with real graphics and real color; this assignment covers some preliminaries. For this assignment you are to define a class A4Checkerboard with two constructors and a draw() method as described below.

One constructor is to take 2 character arguments. The checkerboard that is represented by the A4Checkerboard class is to be represented in terms of these two characters. In particular, the checkerboard is to be drawn using only these two characters.

The second constructor is to be a zero-argument constructor that prompts the user for the two characters to be used in the representation. You may use the JOptionPane.showInputDialog method of Chapter 3 to get these characters. However note that this method will return a string and not a character. There is also no guarantee that this string will be of length 1. If the string has greater than 1 (or exactly 1), you should use its first character. Otherwise you should use the default character 'X' for the first character and 'O' for the second. You can obtain these values automatically by constructing a string consisting of the user's input string followed by the default character, and then extracting the first character of the resulting string.

The draw method is to draw the checkerboard onto System.out. The checkerboard should appear as an 8 by 8 array of characters, using only the two characters that represent the checkerboard. The checkerboard that is drawn should have the usual checkerboard property that none of the 4 characters adjacent to a given character are equal to that given character.

It will be helpful to define one or more private methods that the public methods may invoke. For example, a drawRow or drawColumn method might be helpful in implementing the draw method. Note that such a method will have to be able to draw rows or columns starting with each of the two characters of the checkerboard. Your second constructor may also use a private method to get and verify the user input.

For this assignment, you should provide a copy of your code on diskette or CD (no email), and hard copies of your code and of the results of your testing. The testing should be done with the A4 class, which is available on the class web site. Note that the main method for this class invokes the zero-argument constructor three times. For these three tests, you should provide the three pairs of inputs "hey" and "you", "-" and "|", and "" and "" (two empty strings).

Don't forget to document

You should know which comments are appropriate for Javadoc and which are not, but you will not be judged harshly on the syntax of your Javadoc comments.