// ------------------------------------------------------------------------- /** * A palette is a stack of bricks on a wooden base. * This class is a part of an application for a company producing bricks. * Bricks are delivered in palettes (stacks of bricks). This class * is supposed to provide methods telling its height and weight. * * There are (at least) four errors in this project. Find them. Fix them. * * @author Michael Kolling * @version 2002.02.08 */ public class Palette { //~ Instance/static variables ............................................. private Brick aBrick; private int bricksInPlane; private int height; // constants: private static final double BASE_WEIGHT = 6.5; // in kg private static final double BASE_HEIGHT = 15; // in cm //~ Constructors .......................................................... // ---------------------------------------------------------- /** * Create a palette with a given number of bricks. The bricks are * all 8cm x 20cm x 12cm. * @param numBricksInPlane is the number of bricks in each level on the * base * @param stackHeight is the number of bricks stacked on top of each * other */ public Palette( int numBricksInPlane, int stackHeight ) { aBrick = new Brick( 8, 20, 12 ); bricksInPlane = numBricksInPlane; height = stackHeight; } //~ Methods ............................................................... // ---------------------------------------------------------- /** * Get the weight of this palette. * @return the weight of the palette (in kg) */ public double getWeight() { int numberOfBricks = bricksInPlane * height; return aBrick.getWeight() * numberOfBricks; } // ---------------------------------------------------------- /** * Get the height of this palette. * return the height of this stack (in cm) */ public double getHeight() { return ( aBrick.getHeight() % height ) + BASE_HEIGHT; } }