15a-class-examples

15a-class-examples - /* Number of rows */ private static...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Handout #15A CS 106A July 1, 2009 Solution to the Checkerboard Problem /* * File: Checkerboard.java * ----------------------- * This program draws a checkerboard. */ import acm.graphics.*; import acm.program.*; /** * This class draws a checkerboard on the graphics window. * The size of the checkerboard is specified by the * constants NROWS and NCOLUMNS, and the checkboard fills * the vertical space available. */ public class Checkerboard extends GraphicsProgram {
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: /* Number of rows */ private static final int NROWS = 8; /* Number of columns */ private static final int NCOLUMNS = 8; /* Runs the program */ public void run() { int sqSize = getHeight() / NROWS; for (int i = 0; i < NROWS; i++) { for (int j = 0; j < NCOLUMNS; j++) { int x = j * sqSize; int y = i * sqSize; GRect sq = new GRect(x, y, sqSize, sqSize); sq.setFilled((i + j) % 2 != 0); add(sq); } } } }...
View Full Document

This note was uploaded on 10/14/2010 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Ask a homework question - tutors are online