-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusershape.java
61 lines (60 loc) · 1023 Bytes
/
usershape.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
import java.util.*;
abstract class shape
{
abstract void cal_area();
abstract void cal_volume();
}
class sphere extends shape
{
float r;
sphere(float r)
{
this.r=r;
}
void cal_area()
{
float a=4*3.14f*r*r;
System.out.println("\nArea of sphere = "+a);
}
void cal_volume()
{
float v=(4/3)*3.14f*r*r*r;
System.out.println("\nVolume of sphere = "+v);
}
}
class cone extends shape
{
float r,h;
cone(float r,float h)
{
this.r=r;
this.h=h;
}
void cal_area()
{
float a=3.14f*r*(r+h*h+r*r);
System.out.println("\nArea of cone = "+a);
}
void cal_volume()
{
float v=3.14f*r*r*(h/3);
System.out.println("\nVolume of cone = "+v);
}
}
class Mdemo
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter Radius = ");
float r=sc.nextFloat();
System.out.print("Enter Height = ");
float h=sc.nextFloat();
sphere ob=new sphere(r);
ob.cal_area();
ob.cal_volume();
cone ob1=new cone(r,h);
ob1.cal_area();
ob1.cal_volume();
}
}