// SquareWorld.java // Use a turtle to draw a "staircase" of squares import java.awt.Color; public class SquareWorld extends TurtleWorld { // SquareWorld is a subclass of TurtleWorld // define class constant(s) private static final double START_LENGTH = 150; private static final int START_LEVELS = 4; private static final double SHRINK_FACTOR = 0.5; // specifies the next box's relative side // length; e.g., if the current side length // is 80, then the next side length is 40 private static final Color START_COLOR = Color.BLUE; // declare instance variable(s) private SquareTurtle tammy; // we'll call our turtle "tammy" // define constructor method to initialize instance variable(s) public SquareWorld () { tammy = new SquareTurtle(); // move towards top left tammy.penUp(); tammy.backward(100); tammy.left(90); tammy.forward(100); tammy.right(90); tammy.penDown(); // set color tammy.setColor(START_COLOR); } // define the behavior when the "run" button is clicked public void run() { // draw the staircase tammy.drawStaircase(START_LENGTH, START_LEVELS, SHRINK_FACTOR); } // create a new SquareWorld // (this puts a graphics window on the screen // and invokes the SquareWorld constructor method) public static void main(String[] args) { new SquareWorld(); } }