public class UseShapesRx
{
public static void main (String[] args)
{
RectangleRx rect1 = new RectangleRx(2,4);
BoxRx bv = new BoxRx(5,5,5);
System.out.println("The area of the rectangle is " + rect1.area());
System.out.println("The volume of the box is " + bv.volume());
BoxRx boxOne = new BoxRx(1, 2, 3);
BoxRx boxTwo = new BoxRx(4, 5, 6);
System.out.println("The surface area of boxOne is " +boxOne.area());
System.out.println("The surface area of boxTwo is " +boxTwo.area());
}
}
public class BoxRx extends RectangleRx
{
protected double depth;
public BoxRx(double lh, double wh, double dh)
{
super(lh, wh);
depth = dh;
}
public double area()
{
//surface area of box = 2(h*w) + 2(h*l) + 2(w*l)
double area = 2*(length*width + width*depth + length*depth);
return area;
}
public double volume()
{
return width * length * depth;
}
}