Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/main/java/com/thealgorithms/maths/Area.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,22 @@ public static double surfaceAreaSphere(final double radius) {
* @param slantHeight slant height of the pyramid
* @return surface area of the given pyramid
*/
public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) {
public static double surfaceAreaPyramid(
final double sideLength, final double slantHeight) {

if (sideLength <= 0) {
throw new IllegalArgumentException("");
throw new IllegalArgumentException(
"side length must be greater than 0");
}

if (slantHeight <= 0) {
throw new IllegalArgumentException("slant height must be greater than 0");
throw new IllegalArgumentException(
"slant height must be greater than 0");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review: The slant-height check rejects zero and negative values. Automated tests should verify that both cases throw IllegalArgumentException.

}
double baseArea = sideLength * sideLength;
double lateralSurfaceArea = 2 * sideLength * slantHeight;

final double baseArea = sideLength * sideLength;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review: Declaring the calculation variables final makes it clear that they are not reassigned. The surface-area formula remains unchanged.

final double lateralSurfaceArea = 2 * sideLength * slantHeight;

return baseArea + lateralSurfaceArea;
}

Expand Down
Loading