forked from mohammedabdulbari/Java-SE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CylinderTest.java
82 lines (72 loc) · 1.53 KB
/
CylinderTest.java
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
package cylindertest;
class Cylinder
{
private int radius;
private int height;
public Cylinder()
{
radius=height=1;
}
public Cylinder(int r,int h)
{
radius=r;
height=h;
}
public int getHeight()
{
return height;
}
public int getRadius()
{
return radius;
}
public void setHeight(int h)
{
if(h>=0)
height=h;
else
height=0;
}
public void setRadius(int r)
{
if(r>=0)
radius=r;
else
radius=0;
}
public void setDimensions(int h,int r)
{
height=h;
radius=r;
}
public double lidArea()
{
return Math.PI*radius*radius;
}
public double perimeter()
{
return 2*Math.PI*radius;
}
public double drumArea()
{
return 2*lidArea()+perimeter()*height;
}
public double volume()
{
return lidArea()*height;
}
}
public class CylinderTest {
public static void main(String[] args) {
Cylinder c=new Cylinder();
c.setHeight(10);
c.setRadius(7);
c.setDimensions(10, 7);
System.out.println("LidArea "+c.lidArea());
System.out.println("Circumference "+c.perimeter());
System.out.println("totalSurfaceArea "+c.drumArea());
System.out.println("Volume "+c.volume());
System.out.println("Height"+c.getHeight());
System.out.println("Radius"+c.getRadius());
}
}