Skip to content

Commit bb087b5

Browse files
committed
Added surface area calculation for pyramid
1 parent 648572a commit bb087b5

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ Please read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute
1818

1919
## Algorithms
2020
Our [directory](DIRECTORY.md) has the full list of applications.
21+
22+
THIS IS MY CHANGES.

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,24 @@ public static double surfaceAreaCone(final double radius, final double height) {
192192
}
193193
return Math.PI * radius * (radius + Math.pow(height * height + radius * radius, 0.5));
194194
}
195+
196+
197+
/**
198+
* Calculate the surface area of a pyramid with a square base.
199+
*
200+
* @param sideLength side length of the square base
201+
* @param slantHeight slant height of the pyramid
202+
* @return surface area of the given pyramid
203+
*/
204+
public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) {
205+
if (sideLength <= 0) {
206+
throw new IllegalArgumentException("Must be a positive sideLength");
207+
}
208+
if (slantHeight <= 0) {
209+
throw new IllegalArgumentException("Must be a positive slantHeight");
210+
}
211+
double baseArea = sideLength * sideLength;
212+
double lateralSurfaceArea = 2 * sideLength * slantHeight;
213+
return baseArea + lateralSurfaceArea;
214+
}
195215
}

0 commit comments

Comments
 (0)