lavina
04-14-2004, 11:59 AM
Hi, I need to debug these two small projects and I can't really seem to find anything wrong with it. I'm new at this and the project does have errors but I can not seem to find them. Here is the project:
/**
* A palette is a stack of bricks on a wooden base.
*
* @author: Michael Kolling
* @version: 2002.02.08
*/
public class Palette
{
// constants:
private static final double baseWeight = 6.5; // in kg
private static final double baseHeight = 15; // in cm
private Brick aBrick;
private int bricksInPlane;
private int height;
/**
* Create a palette with a given number of bricks.
* 'bricksInPlane' is the number of bricks in each level on the base.
* 'height' is the number of bricks stacked on top of each other.
*/
public Palette(int bricksInPlane, int height)
{
this.bricksInPlane = bricksInPlane;
this.height = height;
aBrick = new Brick(8, 20, 12);
}
/**
* Return the base of the palette (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) + baseHeight;
}
}
Project 2:
/**
* Class Brick - models a simple brick.
*
* @author: Michael Kolling
* @version: 2002.02.08
*/
public class Brick
{
// Constant.
private static final int WEIGHT_PER_CM3 = 2; // weight per cubic cm in grams
// instance variables:
private int height;
private int width;
private int depth;
/**
* Create a Brick. Parameters are edge lengths in centimeters.
*/
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 + side2 + 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 qubic centimeters.
*/
public int getVolume()
{
return width * height * depth;
}
public double getHeight()
{
return height;
}
}
/**
* A palette is a stack of bricks on a wooden base.
*
* @author: Michael Kolling
* @version: 2002.02.08
*/
public class Palette
{
// constants:
private static final double baseWeight = 6.5; // in kg
private static final double baseHeight = 15; // in cm
private Brick aBrick;
private int bricksInPlane;
private int height;
/**
* Create a palette with a given number of bricks.
* 'bricksInPlane' is the number of bricks in each level on the base.
* 'height' is the number of bricks stacked on top of each other.
*/
public Palette(int bricksInPlane, int height)
{
this.bricksInPlane = bricksInPlane;
this.height = height;
aBrick = new Brick(8, 20, 12);
}
/**
* Return the base of the palette (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) + baseHeight;
}
}
Project 2:
/**
* Class Brick - models a simple brick.
*
* @author: Michael Kolling
* @version: 2002.02.08
*/
public class Brick
{
// Constant.
private static final int WEIGHT_PER_CM3 = 2; // weight per cubic cm in grams
// instance variables:
private int height;
private int width;
private int depth;
/**
* Create a Brick. Parameters are edge lengths in centimeters.
*/
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 + side2 + 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 qubic centimeters.
*/
public int getVolume()
{
return width * height * depth;
}
public double getHeight()
{
return height;
}
}