import interfacePackage.ShapesInterface; public class Cube implements ShapesInterface { privatefinaldoubleLENGTH; privatefinaldoubleWIDTH; privatefinaldoubleHEIGHT; privatefinaldoubleVOLUME; privatefinaldoubleSURFACE_AREA; privatefinaldoubleBASE_AREA; privatefinal String SHAPE = "Cube";
I need help creating a Java code package in Cube and Square classes as described in the image below
package objectsPackage;
import interfacePackage.ShapesInterface;
public class Cube implements ShapesInterface
{
privatefinaldoubleLENGTH;
privatefinaldoubleWIDTH;
privatefinaldoubleHEIGHT;
privatefinaldoubleVOLUME;
privatefinaldoubleSURFACE_AREA;
privatefinaldoubleBASE_AREA;
privatefinal String SHAPE = "Cube";
public Cube()
{
this.HEIGHT = Math.random() * 10;
this.LENGTH = calculateLength();
this.CUBE_AREA = calculateConeArea();
this.BASE_AREA = calculateBaseArea();
this.SURFACE_AREA = calculateSurfaceArea();
this.VOLUME = calculateVolume();
}
@Override
publicdouble getArea() {
// TODO Auto-generated method stub
returnthis.SURFACE_AREA;
}
@Override
publicdouble getVolume() {
// TODO Auto-generated method stub
returnthis.VOLUME;
}
@Override
publicvoid displayArea() {
System.out.printf("This is a %s with an area of %3.2f square units%n",SHAPE, SURFACE_AREA);
}
@Override
publicvoid displayVolume() {
System.out.printf("This is a %s with a volume of %3.2f cubic units%n",SHAPE, VOLUME);
}
public String toString()
{
returnSHAPE;
}
}
Step by step
Solved in 3 steps