Skip to content

Commit 19888ce

Browse files
commit
1 parent 873dd97 commit 19888ce

File tree

1 file changed

+22
-0
lines changed
  • src/main/java/com/thealgorithms/maths

1 file changed

+22
-0
lines changed

src/main/java/com/thealgorithms/maths/Area.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
package com.thealgorithms.maths;
24

35
/**
@@ -129,6 +131,26 @@ public static double surfaceAreaParallelogram(final double base, final double he
129131
return base * height;
130132
}
131133

134+
/**
135+
* Calculate the surface area of a pyramid with a square base.
136+
*
137+
* @param sideLength side length of the square base
138+
* @param slantHeight slant height of the pyramid
139+
* @return surface area of the given pyramid
140+
*/
141+
public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) {
142+
if (sideLength <= 0) {
143+
throw new IllegalArgumentException("Must be a positive sideLength");
144+
}
145+
if (slantHeight <= 0) {
146+
throw new IllegalArgumentException("Must be a positive slantHeight");
147+
}
148+
double baseArea = sideLength * sideLength;
149+
double lateralSurfaceArea = 2 * sideLength * slantHeight;
150+
return baseArea + lateralSurfaceArea;
151+
}
152+
153+
132154
/**
133155
* Calculate the area of a trapezium.
134156
*

0 commit comments

Comments
 (0)