public class Box extends Rectangle { private int depth; public Box(int theWidth, int theHeight, int theDepth) { // Call base class constructor. super(theWidth, theHeight); // Only nonnegative depth is allowed if (theDepth > 0) depth = theDepth; else depth = 0; } public int getVolume( ) { return depth * getArea( ); } public String toString( ) { String temp = super.toString( ); int index = temp.indexOf(" area"); temp = temp.substring(0, index); return String.format("%sx%d volume=%d", temp, depth, getVolume( )); } public static void main(String[ ] args) { Box r = new Box(12, 15, 10); System.out.println("Volume of r is " + r.getVolume( )); System.out.println("toString output of r is "); System.out.println(r); System.out.println(r); // Test behavior of negative depth in constructor. System.out.println(new Box(-5, 15, 10)); System.out.println(new Box(12, -8, 10)); System.out.println(new Box(-5, -8, 10)); System.out.println(new Box(-5, 15, -3)); System.out.println(new Box(12, -8, -3)); System.out.println(new Box(-5, -8, -3)); } }