1 /**
2 This class describes pyramids with a square base.
3 */
4 public class Pyramid
5 {
6 private double height;
7 private double baseLength;
8
9 /**
10 Constructs a pyramid with a given height and baselength.
11 @param height the height
12 @param baseLength the length of one of the sides of the square base
13 */
14 public Pyramid(double height, double baseLength)
15 {
16 this.height = height;
17 this.baseLength = baseLength;
18 }
19
20 /**
21 Gets the volume of this pyramid.
22 @return the volume
23 */
24 public double getVolume()
25 {
26 return height * baseLength * baseLength / 3;
27 }
28
29 /**
30 Gets the surface area of this pyramid.
31 @return the surface area, not including the base
32 */
33 public double getSurfaceArea()
34 {
35 double sideLength = Math.sqrt(height * height
36 + baseLength * baseLength / 4);
37 return 2 * baseLength * sideLength;
38 }
39 }