Pyramid - private static final int BRICK_HEIGHT = 12; p /**...

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

View Full Document Right Arrow Icon
/* * File: Pyramid.java * Name: * Section Leader: * ------------------ * This file is the starter file for the Pyramid problem. * It includes definitions of the constants that match the * sample run in the assignment, but you should make sure * that changing these values causes the generated display * to change accordingly. */ import acm.graphics.*; import acm.program.*; import java.awt.*; i @SuppressWarnings("unused") public class Pyramid extends GraphicsProgram { p /** Width of each brick in pixels */ private static final int BRICK_WIDTH = 30; p /** Width of each brick in pixels */
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: private static final int BRICK_HEIGHT = 12; p /** Number of bricks in the base of the pyramid */ private static final int BRICKS_IN_BASE = 14; p public void run() { p int x,y; y=getHeight(); x=getWidth(); for(int i=BRICKS_IN_BASE;i>0;i--){ brickRow(i,(x/2)-(BRICK_WIDTH*(i/2.0)),y-((BRICKS_IN_BASE-i+1)*BRICK_HEIGHT)); } } private void brickRow(int noofbricks,double xloc, int yloc){ for(int i=0;i<noofbricks;i++){ add(new GRect(xloc+ (i*BRICK_WIDTH),yloc,BRICK_WIDTH,BRICK_HEIGHT)); ( } } }...
View Full Document

Ask a homework question - tutors are online