-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask9.java
More file actions
88 lines (88 loc) · 3.12 KB
/
Task9.java
File metadata and controls
88 lines (88 loc) · 3.12 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
87
88
/*Write a Java program to accept a figure code and find the areas of
different geometrical figures such as circle, square, rectangle etc.
using switch.*/
import java.util.*;
class FindArea
{
public static void main(String... args)
{
Scanner s=new Scanner(System.in);
double a,b,h;
double pie=3.14159,Area,angle;
int n; //N is for case number
System.out.println("Enter 1 for Triangle");
System.out.println("Enter 2 for Square");
System.out.println("Enter 3 for Rectangle");
System.out.println("Enter 4 for Parallelogram");
System.out.println("Enter 5 for Trapezoid");
System.out.println("Enter 6 for Circle");
System.out.println("Enter 7 for Ellips");
System.out.println("Enter 8 for Sector");
n=s.nextInt();
switch(n)
{
case 1:
System.out.print("Enter the base:");
b=s.nextDouble();
System.out.print("Enter the height:");
h=s.nextDouble();
Area=(b*h)/2;
System.out.print("Area of Triangle="+Area+" unit^2");
break;
case 2:
System.out.print("Enter the side of square:");
a=s.nextDouble();
Area=(a*a);
System.out.print("Area of Square="+Area+" unit^2");
break;
case 3:
System.out.print("Enter the height of rectangle:");
h=s.nextDouble();
System.out.print("Enter the width of rectangle:");
b=s.nextDouble();
Area=(h*b);
System.out.print("Area of Rectangle="+Area+" unit^2");
break;
case 4:
System.out.print("Enter the height of parallelogram:");
h=s.nextDouble();
System.out.print("Enter the width of parallelogram:");
b=s.nextDouble();
Area=(h*b);
System.out.print("Area of Parallelogram="+Area+" unit^2");
break;
case 5:
System.out.print("Enter the distance across the top:");
a=s.nextDouble();
System.out.print("Enter the distance across the base:");
b=s.nextDouble();
System.out.println("Enter the value of vertical height:");
h=s.nextDouble();
Area=((a+b)*h)/2;
System.out.print("Area of Trapezoid="+Area+" unit^2");
break;
case 6:
System.out.print("Enter the radius of circle:");
a=s.nextDouble();
Area=pie*a*a;
System.out.print("Area of Circle="+Area+" unit^2");
break;
case 7:
System.out.print("length of semi-minor axis:");
a=s.nextDouble();
System.out.print("length of semi-major axis:");
b=s.nextDouble();
Area=(a*b*pie);
System.out.print("Area of Ellipse="+Area+" unit^2");
break;
case 8:
System.out.print("Enter the radius:");
a=s.nextDouble();
System.out.print("Enter the value of angle in radian(1 degree=0.0175 radian):");
b=s.nextDouble();
Area=(a*b*pie);
System.out.print("Area of Sector="+Area+" unit^2");
break;
}
}
}