public class Q236190345 {
public static void main(String[] args) {
var rectangle = new Rectangle(6, 6);
System.out.println(rectangle.calcSquare() + " == 36");
var parallelepiped = new Parallelepiped(6, 6, 6);
System.out.println(parallelepiped.calcVolume() + " == 216");
System.out.println(parallelepiped.calcSquare() + " == 216");
}
}
class Rectangle {
private final double length;
private final double width;
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
public double getLength() {
return length;
}
public double getWidth() {
return width;
}
public double calcSquare() {
return getLength() * getWidth();
}
}
class Parallelepiped extends Rectangle {
private final double height;
public Parallelepiped(double length, double width, double height) {
super(length, width);
this.height = height;
}
public double getHeight() {
return height;
}
@Override
public double calcSquare() {
return 2 * (getLength() * getWidth() + getWidth() * getHeight() + getHeight() * getLength());
}
public double calcVolume() {
return getLength() * getWidth() * getHeight();
}
}