forked from dharmanshu1921/Daa-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShreshth.java
More file actions
86 lines (76 loc) · 1.83 KB
/
Shreshth.java
File metadata and controls
86 lines (76 loc) · 1.83 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.util.*;
abstract class shape{
}
class circle extends shape{
public circle(int r) {
double a=3.14*r*r;
System.out.println("Area of circle = "+a);
}
}
class triangle extends shape{
public triangle(int b, int h) {
double a=b*h/2;
System.out.println("Area of triangle = "+a);
}
}
class square extends shape{
public square(int s) {
double a= s*s;
System.out.println("Area of square = "+a);
}
}
class rectangle extends shape{
public rectangle(int l, int b) {
double a=l*b;
System.out.println("Area of rectangle = "+a);
}
}
public class shapes {
public static void main(String[] args) {
boolean x = true;
while (x==true) {
System.out.println("Select Option: ");
System.out.println("1) Circle");
System.out.println("2) Triangle");
System.out.println("3) Square");
System.out.println("4) Rectangle");
System.out.println("5) Exit");
Scanner sc= new Scanner(System.in);
int opt = sc.nextInt();
if (opt == 1)
{
System.out.println("Enter Radius: ");
int r=sc.nextInt();
circle c= new circle(r);
}
else if (opt == 2)
{
System.out.println("Enter Base: ");
int b=sc.nextInt();
System.out.println("Enter Height: ");
int h=sc.nextInt();
triangle t= new triangle(b,h);
}
else if (opt == 3)
{
System.out.println("Enter Side: ");
int s=sc.nextInt();
square sq= new square(s);
}
else if (opt == 4)
{
System.out.println("Enter Length: ");
int l=sc.nextInt();
System.out.println("Enter Breadth: ");
int b=sc.nextInt();
rectangle r= new rectangle(l,b);
}
else if (opt == 5)
{
x=false;
} else {
System.out.println("Invalid Option");
}
}
}
}