-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEquilateralPyramid.java
More file actions
33 lines (28 loc) · 905 Bytes
/
EquilateralPyramid.java
File metadata and controls
33 lines (28 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class EquilateralPyramid extends Shape implements Volume {
private double baseSide, height;
public EquilateralPyramid(double baseSide, double height) {
super("Equilateral Pyramid");
this.baseSide = baseSide;
this.height = height;
}
@Override
double calculateArea() {
double baseArea = baseSide * baseSide;
double slantHeight = Math.sqrt((baseSide / 2) * (baseSide / 2) + height * height);
double lateralArea = 2 * baseSide * slantHeight;
return baseArea + lateralArea;
}
@Override
double calculatePerimeter() {
return 4 * baseSide;
}
@Override
public double calculateVolume() {
return (1.0 / 3) * (baseSide * baseSide) * height;
}
@Override
public void displayResults() {
super.displayResults();
System.out.println("Volume: " + calculateVolume());
}
}