-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterVolume(1).java
More file actions
52 lines (39 loc) · 1.09 KB
/
Copy pathinterVolume(1).java
File metadata and controls
52 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
49
50
51
import java.util.Scanner;
interface Volume {
Scanner in = new Scanner(System.in);
double pi = 3.14;
void readData();
double displayVolume();
}
class Sphere implements Volume {
int radius;
public void readData() {
System.out.println("Enter radius");
radius = in.nextInt();
}
public double displayVolume() {
return (4.0 / 3.0) * pi * radius * radius * radius;
}
}
class Cylinder implements Volume {
int radius, height;
public void readData() {
System.out.println("Enter radius");
radius = in.nextInt();
System.out.println("Enter height");
height = in.nextInt();
}
public double displayVolume() {
return pi * radius * radius * height;
}
}
class InterVolume {
public static void main(String args[]) {
Sphere obs = new Sphere();
Cylinder obc = new Cylinder();
obs.readData();
System.out.println("Volume of sphere = " + obs.displayVolume());
obc.readData();
System.out.println("\nVolume of cylinder = " + obc.displayVolume());
}
}