forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVolume.java
More file actions
91 lines (82 loc) · 2.35 KB
/
Volume.java
File metadata and controls
91 lines (82 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.thealgorithms.maths;
/* Find volume of various shapes.*/
public class Volume {
/**
* Calculate the volume of a cube.
*
* @param sideLength side length of cube
* @return volume of given cube
*/
public static double volumeCube(double sidelength) {
return sidelength * sidelength * sidelength;
}
/**
* Calculate the volume of a cuboid.
*
* @param width of cuboid
* @param height of cuboid
* @param length of cuboid
* @return volume of given cuboid
*/
public static double volumeCuboid(double width, double height, double length) {
return width * height * length;
}
/**
* Calculate the volume of a sphere.
*
* @param radius radius of sphere
* @return volume of given sphere
*/
public static double volumeSphere(double radius) {
return (4 * Math.PI * radius * radius * radius) / 3;
}
/**
* Calculate volume of a cylinder
*
* @param radius radius of the floor
* @param height height of the cylinder.
* @return volume of given cylinder
*/
public static double volumeCylinder(double radius, double height) {
return Math.PI * radius * radius * height;
}
/**
* Calculate the volume of a hemisphere.
*
* @param radius radius of hemisphere
* @return volume of given hemisphere
*/
public static double volumeHemisphere(double radius) {
return (2 * Math.PI * radius * radius * radius) / 3;
}
/**
* Calculate the volume of a cone.
*
* @param radius radius of cone.
* @param height of cone.
* @return volume of given cone.
*/
public 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.
*/
public 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.
*/
public static double volumePyramid(double basearea, double height) {
return (basearea * height) / 3;
}
}