Skip to content
Open
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
19 changes: 19 additions & 0 deletions src/main/java/com/thealgorithms/maths/Area.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.maths;

Check failure on line 1 in src/main/java/com/thealgorithms/maths/Area.java

View workflow job for this annotation

GitHub Actions / build

unnamed class should not have package declaration

Check failure on line 1 in src/main/java/com/thealgorithms/maths/Area.java

View workflow job for this annotation

GitHub Actions / build

unnamed class should not have package declaration

Check failure on line 1 in src/main/java/com/thealgorithms/maths/Area.java

View workflow job for this annotation

GitHub Actions / AnalyzeJava

unnamed class should not have package declaration

Check failure on line 1 in src/main/java/com/thealgorithms/maths/Area.java

View workflow job for this annotation

GitHub Actions / AnalyzeJava

unnamed class should not have package declaration

/**
* Find the area of various geometric shapes
Expand Down Expand Up @@ -233,3 +233,22 @@
return Math.PI * radius * (radius + Math.pow(height * height + radius * radius, 0.5));
}
}

/**
* Calculate the surface area of a pyramid with a square base.
*
* @param sideLength side length of the square base
* @param slantHeight slant height of the pyramid
* @return surface area of the given pyramid
*/
public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) {

Check failure on line 244 in src/main/java/com/thealgorithms/maths/Area.java

View workflow job for this annotation

GitHub Actions / build

unnamed classes are a preview feature and are disabled by default.

Check failure on line 244 in src/main/java/com/thealgorithms/maths/Area.java

View workflow job for this annotation

GitHub Actions / build

unnamed classes are a preview feature and are disabled by default.

Check failure on line 244 in src/main/java/com/thealgorithms/maths/Area.java

View workflow job for this annotation

GitHub Actions / AnalyzeJava

unnamed classes are a preview feature and are disabled by default.

Check failure on line 244 in src/main/java/com/thealgorithms/maths/Area.java

View workflow job for this annotation

GitHub Actions / AnalyzeJava

unnamed classes are a preview feature and are disabled by default.
if (sideLength <= 0) {
throw new IllegalArgumentException("Must be a positive sideLength");
}
if (slantHeight <= 0) {
throw new IllegalArgumentException("Must be a positive slantHeight");
}
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.

simple calculation of base times height :)

double lateralSurfaceArea = 2 * sideLength * slantHeight;
return baseArea + lateralSurfaceArea;
}
Loading