-
Notifications
You must be signed in to change notification settings - Fork 0
/
AreaOfShapes.java
74 lines (60 loc) · 1.75 KB
/
AreaOfShapes.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
import java.util.*;
class Shapes{
static double area(double r){
return 3.14*r*r;
}
static double area(int w, double l, double b){
if (w == 2)
return l*b;
else
return 0.5*l*b;
}
}
class AreaOfShapes{
public static void main(String a[]){
Scanner sc = new Scanner(System.in);
Shapes obj = new Shapes();
int flag = 1;
double result, tempb, templ, tempr, temph;
System.out.println("\n================ OPTIONS ================");
System.out.println("\t1 - Circle");
System.out.println("\t2 - Rectangle");
System.out.println("\t3 - Triangle");
System.out.println("\t4 - Exit");
System.out.println("=========================================\n");
while(flag == 1){
System.out.print("Enter Your Option: ");
int o = sc.nextInt();
switch(o){
case 1:
System.out.print("\nEnter The Radius Of Circle: ");
tempr = sc.nextDouble();
result = obj.area(tempr);
System.out.println("Area Of Circle: " + result);
break;
case 2:
System.out.print("\nEnter The Length Of Rectangle: ");
templ = sc.nextDouble();
System.out.print("Enter The Breadth Of Rectangle: ");
tempb = sc.nextDouble();
result = obj.area(2, templ, tempb);
System.out.println("Area Of Rectangle: " + result);
break;
case 3:
System.out.print("\nEnter The Base Of Triangle: ");
tempb = sc.nextDouble();
System.out.print("Enter The Height Of Triangle: ");
temph = sc.nextDouble();
result = obj.area(3, tempb, temph);
System.out.println("Area Of Traingle: " + result);
break;
case 4:
System.out.print("\nClosing...");
flag = 0;
break;
default:
System.out.print("\nPlease Enter A Valid Option!");
}
}
}
}