New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added volume of prism and pyramid #2902

Merged
merged 1 commit into from Jan 10, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -23,6 +23,12 @@ public static void main(String[] args) {

/* test cone */
assert Double.compare(volumeCone(5, 7), 916.297857297023) == 0;

/*test prism*/
assert Double.compare(volumePrism(10, 2), 20.0) == 0;

/*test pyramid*/
assert Double.compare(volumePyramid(10, 3), 10.0) == 0;

}

@@ -89,4 +95,26 @@ private static double volumeHemisphere(double radius) {
private static double volumeCone(double radius, double height) {
return Math.PI * radius * radius * height / 3;
}

/**
* Calculate the volume of a prism.
*
* @param area of the base.
* @param height of prism.
* @return volume of given prism.
*/
private static double volumePrism(double basearea, double height) {
return basearea * height;
}

/**
* Calculate the volume of a pyramid.
*
* @param area of the base.
* @param height of pyramid.
* @return volume of given pyramid.
*/
private static double volumePyramid(double basearea, double height) {
return basearea * height / 3;
}
}
Added volume of prism and pyramid by Harpia-Vieillot · Pull Request #2902 · TheAlgorithms/Java · GitHub
12 11