Java Reference
In-Depth Information
public
BoxFigure(
double
l,
double
w,
double
h)
{
super
(l, w);
if
(h >= 0)
height = h;
else
height = 0;
}
public void
setDimension(
double
l,
double
w,
double
h)
{
super
.setDimension(l, w);
if
(h >= 0)
height = h;
else
height = 0;
}
public double
getHeight()
{
return
height;
}
public double
area()
{
return
2 * (getLength() * getWidth()
+ getLength() * height
+ getWidth() * height);
}
public double
volume()
{
1
0
return super
.area() * height;
}
public
String toString()
{
return
("Length = " + getLength()
+ "; Width = " + getWidth()
+ "; Height = " + height
+ "\n"
+ "Surface Area = " + area()
+ "; Volume = " + volume());
}
}
Note that the
class
BoxFigure
is derived from the
class
RectangleFigure
. The
definition of the
class
BoxFigure
is similar to the definition of the
class
Box
given
previously. The method
toString
of the
class
BoxFigure
, in addition to returning
the length, width, and height, also returns the surface area and volume of the box.
Search WWH ::
Custom Search