-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ_40.java
78 lines (71 loc) · 1.45 KB
/
Q_40.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package Q40;
import java.util.Scanner;
class Shape{
String type;
Scanner sc=new Scanner(System.in);
String getName() {
type=sc.nextLine();
return type;
}
}
class TwoDim extends Shape{
double area(double radius) {
return 3.14*radius*radius;
}
double volume(double radius) {
return 2*3.14*radius;
}
}
class ThreeDim extends Shape{
int area(int side) {
return side*side*side;
}
int volume(int side) {
return 6*side*side;
}
}
public class Q_40 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan=new Scanner(System.in);
String str;
int s;
double r;
int a,v;
double ar,vol;
System.out.println("Enter the side of cube");
s=scan.nextInt();
scan.nextLine();
System.out.println("Enter radius of circle");
r=scan.nextDouble();
scan.nextLine();
TwoDim obj1=new TwoDim();
ThreeDim obj2=new ThreeDim();
System.out.println("Enter the type of shape");
str=obj1.getName();
System.out.println(str);
if(str.equals("twoDim")) {
ar=obj1.area(r);
System.out.println("Area of Circle="+ar);
vol=obj1.volume(r);
System.out.println("Circumference of circle="+vol);
}
else if(str.equals("threeDim")){
a=obj2.area(s);
System.out.println("Area of cube="+a);
v=obj2.volume(s);
System.out.println("volume of cube="+v);
}
}
}
/*Output
Enter the side of cube
2
Enter radius of circle
7.5
Enter the type of shape
threeDim
threeDim
Area of cube=8
volume of cube=24
*/