Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Create a class named Cube that contains a private field called depth. This cl

ID: 3635327 • Letter: 1

Question

1. Create a class named Cube that contains a private field called depth. This class should be a subclass (extends) of the Square class. The constructor should take three parameters used to initialize the base class and it’s own ‘depth’ member field.
2.Create a method named computeSurfaceArea() that calculates the surface area of the cube. This method should override the parent method. This method should return the surface are of the cube (width x height x depth). You may not directly access the height and width fields of the parent class.

Need to modify the below program...Could you modify or direct me on how to?

//Square class
public class square
{
private double height;
private double width;
public square()
{
}
public square(double h,double w)
{
height=h;
width=w;
}

public double SurfaceArea()
{
return height*width;
}

}
------------------------------------------------------------
//Cube class
public class Cube extends square
{
private double depth;
public Cube(double x,double y,double z)
{
height=x;
width=y;
depth=z;
}
public double computeSurfaceArea()
{
return height*width*depth;
}
}

Explanation / Answer

You'll need to add getter methods into your Square class so the cube can get the dimensions of it after it is instantiated. In the constructor of the cube, you will first call: super(x,y) to create the square object, then you will assign the depth as z. What you have written computeSurfaceArea() is actually going to find the volume of the cube. This is where using the getter methods comes in. A cube has 6 sides, of the following dimensions: 2XY + 2XZ + 2YZ If you get the rest of the program set up right, the following function should work for determining surface area of the cube: public double SurfaceArea() { double SA = 0; SA += 2 * depth * super.getHeight(); SA += 2 * depth * super.getWidth(); SA += 2 * super.getWidth() * super.getHeight(); return SA; }