-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavalab13.java
More file actions
72 lines (62 loc) · 1.57 KB
/
Copy pathjavalab13.java
File metadata and controls
72 lines (62 loc) · 1.57 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
66
67
68
69
70
71
72
import java.util.Scanner;
interface interdemo{
void volume();
}
class cone implements interdemo{
double r,h;
cone(double r,double h)
{
this.r = r;
this.h = h;
}
public void volume(){
System.out.println("volume of cone: " + 0.33*3.14*r*h);
}
}
class cylinder implements interdemo{
double r;
cylinder(double r)
{
this.r = r;
}
public void volume(){
System.out.println("volume of cone: " + 0.66*3.14*r*r*r);
}
}
class hemisphere implements interdemo{
double r, h;
hemisphere(double r, double h)
{
this.r = r;
this.h = h;
}
public void volume(){
System.out.println("volume of cone: " + 3.14*r*2*h);
}
}
public class javalab13 {
public static void main(String[] st)
{
Scanner sc = new Scanner(System.in);
interdemo ob;
System.out.print("Enter height of cone:");
double n1 = sc.nextDouble();
System.out.print("Enter radius of cone:");
double n2 = sc.nextDouble();
cone obj1 = new cone(n2,n1);
ob = obj1;
ob.volume();
System.out.print("Enter radius of cylinder:");
double n3 = sc.nextDouble();
cylinder obj2 = new cylinder(n3);
ob = obj2;
ob.volume();
System.out.print("Enter height of hemisphere:");
double n4 = sc.nextDouble();
System.out.print("Enter radius of hemisphere:");
double n5 = sc.nextDouble();
hemisphere obj3 = new hemisphere(n5,n4);
ob = obj3;
ob.volume();
}
}