A box is a threedimensional object with width height and dep
A box is a three-dimensional object with width, height, and depth.
Complete the following code:
The following class is used to check your work:
Complete the following file:
public class Box
 {
 private double height;
 private double width;
 private double depth;
/**
 Constructs a box with a given side length.
 @param sideLength the length of each side
 */   
 public Box(double h, double w, double d)
 {
 // your work here
 }
/**
 Gets the volume of this box.
 @return the volume
 */
 public double volume()
 {
 // your work here
 }
 
 /**
 Gets the surface area of this box.
 @return the surface area
 */
 public double surfaceArea()
 {
 // your work here
 }
 }
Solution
class Box
 {
 private double height;
 private double width;
 private double depth;
/**
 Constructs a box with a given side length.
 @param sideLength the length of each side
 */   
 public Box(double h, double w, double d)
 {
    height = h;
    width = w;
    depth = d;
 }
/**
 Gets the volume of this box.
 @return the volume
 */
 public double volume()
 {
 return width * height * depth;
 }
 
 /**
 Gets the surface area of this box.
 @return the surface area
 */
 public double surfaceArea()
 {
 return ((2 * height * width) + (2 * width * depth) + (2 * height * depth));
 }
 }
 public class BoxTester
 {
 public static void main(String[] args)
 {
 Box myBox = new Box(10, 10, 10);
 System.out.println((int)myBox.volume());
 System.out.println(\"Expected: 1000\");
 System.out.println((int)myBox.surfaceArea());
 System.out.println(\"Expected: 600\");
 myBox = new Box(10, 20, 30);
 System.out.println((int)myBox.volume());
 System.out.println(\"Expected: 6000\");
 System.out.println((int)myBox.surfaceArea());
 System.out.println(\"Expected: 2200\");
 }
 }
Output:
1000
 Expected: 1000
 600
 Expected: 600
 6000
 Expected: 6000
 2200
 Expected: 2200


