{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Pyramid

# Pyramid - private static final int BRICK_HEIGHT = 12 p...

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

/* * 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 */
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

{[ snackBarMessage ]}

Ask a homework question - tutors are online