public class HexagonalPrism extends Hexagon { private double height; public Hexa
ID: 3672112 • Letter: P
Question
public class HexagonalPrism extends Hexagon {
private double height;
public HexagonalPrism (double height) {
this(height, 1.0, "white", true);
}
public HexagonalPrism (double height, double side, String color, Boolean filled) {
//implement it
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getVolume() {
//implement it
}
}
Complete a class named HexagonalPrism that extends the Hexagon class created in the above programming question. HexagonalPrism has one instance variable (-height: double). The equation for the volume of the hexagonal prism is: volume = 1.5 * Math.sqrt(3.0) * side * side * height. Use the getArea() method from the superclass to compute the volume. A skeleton HexagonalPrism class and a HexagonalPrismTester class are all provided below. Implement the two areas in the class noted with //Implement it. Override the toString() method in the superclass. Provide your implementation of the HexagonalPrism class.
public class HexagonalPrismTester {
public static void main(String[] args) {
HexagonalPrism h1 = new HexagonalPrism(2.0, 1.0, "red", true);
double expectedVolume1 = 1.5 * Math.sqrt(3.0) * 1.0 * 1.0 * 2.0;
if (h1.getVolume() == expectedVolume1)
System.out.println("success");
else
System.out.println("fail");
HexagonalPrism h2 = new Hexagon(20.0, 10.0, "blue", false);
double expectedVolume2 = 1.5 * Math.sqrt(3.0) * 10.0 * 10.0 * 20.0;
if (h2.getVolume() == expectedVolume2)
System.out.println("success");
else
System.out.println("fail");
}
Explanation / Answer
please find the implementations below :
public HexagonalPrism (double height, double side, String color, Boolean filled) {
this(height,side,color,filled);
}
public double getVolume() {
double r = 1.5 * Math.sqrt(3.0) * getSide() * getSide() * getHeight();
return r;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.