-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeek5b.java
More file actions
65 lines (56 loc) · 1.5 KB
/
Week5b.java
File metadata and controls
65 lines (56 loc) · 1.5 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
public class Week5b {
public static void main(String[] args) {
Figure_3D[] Fig = new Figure_3D[3];
Fig[0] = new Cylinder();
Fig[1] = new Cone();
Fig[2] = new Sphere();
Fig[0].volume();
Fig[0].area();
Fig[1].volume();
Fig[1].area();
Fig[2].volume();
Fig[2].area();
}
}
class Figure_3D {
final double p = Math.PI;
double r = 12.3;
double h = 34.5;
double l = 10.5;
void volume() {
System.out.println("Volume of Figure is:");
}
void area() {
System.out.println("Area of Figure is:");
}
}
class Cylinder extends Figure_3D {
void volume() {
double vol = p * Math.pow(r, 2) * h;
System.out.println("Volume of Cylinder is : " + vol);
}
void area() {
double area = 2 * p * r * h;
System.out.println("Area of the Cylinder is : " + area);
}
}
class Cone extends Figure_3D {
void volume() {
double vol = (1.0 / 3.0) * p * Math.pow(r, 2) * h;
System.out.println("Volume of Cone is : " + vol);
}
void area() {
double area = 2 * p * r * l;
System.out.println("Area of the Cone is : " + area);
}
}
class Sphere extends Figure_3D {
void volume() {
double vol = (4.0 / 3.0) * p * Math.pow(r, 3);
System.out.println("Volume of the Sphere is : " + vol);
}
void area() {
double area = (4.0) * p * Math.pow(r, 2);
System.out.println("Area of the Sphere is : " + area);
}
}