-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCylender_sphere_Cone.js
More file actions
44 lines (36 loc) · 949 Bytes
/
Cylender_sphere_Cone.js
File metadata and controls
44 lines (36 loc) · 949 Bytes
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
class Cylinder {
constructor(radius, height) {
this.radius = radius;
this.height = height;
}
getVolume() {
let volume = Math.PI * Math.pow(this.radius, 2) * this.height;
return volume.toFixed(4);
}
}
class Sphere {
constructor(radius) {
this.radius = radius;
}
getVolume() {
let volume = (4/3) * Math.PI * Math.pow(this.radius, 3);
return volume.toFixed(4);
}
}
class Cone {
constructor(radius, height) {
this.radius = radius;
this.height = height;
}
getVolume() {
let volume = (Math.PI * Math.pow(this.radius, 2) * this.height) / 3;
return volume.toFixed(4);
}
}
// Example usage
let cylinder = new Cylinder(2, 5);
console.log(cylinder.getVolume()); // Output: 62.8319
let sphere = new Sphere(3);
console.log(sphere.getVolume()); // Output: 113.0973
let cone = new Cone(4, 6);
console.log(cone.getVolume()); // Output: 100.5309