Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

program have at least 4 errors. needs to find them. public class Brick { // Cons

ID: 3562481 • Letter: P

Question

program have at least 4 errors. needs to find them.

public class Brick
{
// Constant.
private static final int WEIGHT_PER_CM3 = 2; // weight per cubic cm in grams

private int height;
private int width;
private int depth;

/**
* Create a Brick given edge lengths in centimeters.
* @param height The brick's height.
* @param width The brick's width.
* @param depth The brick's depth.
*/
public Brick(int height, int width, int depth)
{
this.height = height;
this.width = width;
this.depth = depth;
}

/**
* @return The surface area of this brick in square centimeters.
*/
public double getSurfaceArea()
{
double side1 = width * height;
double side2 = width * depth;
double side3 = depth * height;
double total = (side1 + side1 + side3) * 2;

return total;
}

/**
* @return The weight of this brick in kg.
*/
public double getWeight()
{
return (getVolume() * WEIGHT_PER_CM3) / 1000;
}

/**
* @return The volume of this brick in cubic centimeters.
*/
public int getVolume()
{
return width * height * depth;
}

/**
* @return The height of this brick in centimeters.
*/
public double getHeight()
{
return height;
}
}

and

public class Pallet
{
private static final double BASE_WEIGHT = 6.5; // in kg
private static final double BASE_HEIGHT = 15; // in cm

private Brick aBrick;
private int bricksInPlane;
private int height;

/**
* Create a pallet with a given number of bricks.
* @param bricksInPlane The number of bricks in each level on the base.
* @param height The number of bricks stacked on top of each other.
*/
public Pallet(int bricksInPlane, int height)
{
this.bricksInPlane = bricksInPlane;
this.height = height;
aBrick = new Brick(8, 20, 12);
}

/**
* @return The base of the pallet (in kg)
*/
public double getWeight()
{
int numberOfBricks = bricksInPlane * height;
return aBrick.getWeight() * numberOfBricks;
}

/**
* @return The height of this stack (in cm)
*/
public double getHeight()
{
return (aBrick.getHeight() % height) + BASE_HEIGHT;
}
}

Explanation / Answer

no errors