-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh09_43_Practice15.java
More file actions
57 lines (45 loc) · 1.48 KB
/
Ch09_43_Practice15.java
File metadata and controls
57 lines (45 loc) · 1.48 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
class cylinder{
int radius;
int height;
// Using Shortcut trick of IntelliJ idea
public cylinder(int radius, int height) {
this.radius = radius;
this.height = height;
}
public int getRadius() {
return radius;
}
public void setRadius(int radius) {
this.radius = radius;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public double surfaceArea(){
return (2*Math.PI*radius*radius) + (2*Math.PI*radius*height);
}public double Volume(){
return Math.PI*radius*radius*height;
}
}
public class Ch09_43_Practice15 {
public static void main(String[] args) {
System.out.println();
// Problem 1-
System.out.println("Problem1:");
cylinder myCylinder = new cylinder(45,20);
// myCylinder.setHeight(20); // Commented in order to use Constructor
// myCylinder.setRadius(45); // Commented in order to use Constructor
System.out.println("Height is: " + myCylinder.getHeight() + "cm");
System.out.println("Radius is: " + myCylinder.getRadius() + "cm");
System.out.println();
// Problem 2-
System.out.println("Surface area and Volume");
System.out.println("Surface Area: " + myCylinder.surfaceArea() + " m²");
System.out.println("Volume: " + myCylinder.Volume() + " m³");
// Problem 3
// Using Constructor now
}
}