Your assignment is to write an applet that draws a checkerboard. The checkerboard should look like this:
Your program should define some constants (i.e., final
variables) that determine the configuration of the checkerboard. You
may name these constants as you wish, but the names should be
descriptive of their intended purposes. The checkerboard should
adhere to the following rules:
Color.red and Color.black.
Note that these specifications make it unnecessary to use input and
output from the console (i.e., don't use Scanner or
System.out).
I'll let you work out how to organize your applet's classes and methods, but I'm happy to give you a hint about how to compute information about the squares. In what follows, let's assume that we number rows and columns from 0, so that the top left square is in row 0, column 0.
If you know the row number and column number of a square, how do you determine whether it's a red or black square?
Here's a cool way. Observe that we can determine the color from the following table:
| Row number | Column number | Square color |
| even | even | black |
| even | odd | red |
| odd | even | red |
| odd | odd | black |
We call whether a number is even or odd its parity.
So all you have to do is determine whether the row parity and column
parity are equal. And, given variables row and
column, how do you determine their parity? You already
know the answer: row % 2 and column % 2.
And you know how to determine whether two numbers are equal.
Turn in a listing of your Java file and a screen shot of your checkerboard. It's OK if you print in black and white.
To take a screen picture on Mac OS X, while you have the graphic output on your screen, use the Grab utility if you have it. On my Mac, it's in the Utilities folder within the Applications folder. If you don't have Grab, then press Command-Shift-4. That is, simultaneously hold down the Command key (the one with the apple and/or the butterfly on it), the Shift key, and 4. You'll see a funny icon. Then drag the mouse over the portion of the screen that you want a picture of. The picture will be saved as a PDF file on your desktop.
On the PC, in the Applet Viewer window, click menu "Applet" and then choose "Print... ." A "Print" dialog box will show up. Just press "OK."
You can see my version by clicking here.
You will want to use the Timer class, as I did in the PsychBoxes.java and Illusion.java programs.
We'll see later this week how to use Timer objects, but
in the meantime you can read about them in Section 8.8 of Lewis and
Loftus.
If you submit the extra credit, submit it as a separate program from the regular version, and also submit a screen shot of your green-and-white checkerboard. Again, it's OK if you print in black and white. Note also that although you will be allowed to resubmit the regular version (assuming that you get a 1 on it and you have not used up your six resubmits), you won't be able to resubmit the extra credit.