-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCyclinder.java
More file actions
48 lines (39 loc) · 1.09 KB
/
Cyclinder.java
File metadata and controls
48 lines (39 loc) · 1.09 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
class Cylinder {
private double radius;
private double height;
// Setter methods
public void setRadius(double radius) {
this.radius = radius;
}
public void setHeight(double height) {
this.height = height;
}
// Getter methods
public double getRadius() {
return radius;
}
public double getHeight() {
return height;
}
// Method to calculate Volume
public double getVolume() {
return Math.PI * radius * radius * height;
}
// Method to calculate Total Surface Area
public double getSurfaceArea() {
return 2 * Math.PI * radius * (radius + height);
}
}
public class Main {
public static void main(String[] args) {
Cylinder c = new Cylinder();
// Set values
c.setRadius(5);
c.setHeight(10);
// Print results
System.out.println("Radius = " + c.getRadius());
System.out.println("Height = " + c.getHeight());
System.out.println("Volume = " + c.getVolume());
System.out.println("Surface Area = " + c.getSurfaceArea());
}
}