forked from amanss00/ForNewbies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharea.java
123 lines (94 loc) · 2.68 KB
/
area.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import java.util.Scanner;
abstract class Shape {
protected double x,y;
/* public void getdata()
{
Scanner sc = new Scanner(System.in);
System.out.println("ENTER THE VALUE OF X = ");
x = sc.nextDouble();
System.out.println("ENTER THE VALUE OF Y = ");
y = sc.nextDouble();
}; */
public abstract void compute_area();
}
class Triangle extends Shape {
public void getdata()
{
Scanner sc =new Scanner(System.in);
System.out.println("ENTER THE BASE LENGTH = ");
x = sc.nextDouble();
System.out.println("ENTER THE HEIGHT = ");
y = sc.nextDouble();
}
public void compute_area()
{
double area;
area = (0.5 * x * y);
System.out.println("THE AREA OF TRIANGLE IS = " + area);
}
}
class Rectangle extends Shape {
public void getdata()
{
Scanner sc = new Scanner(System.in);
System.out.println("ENTER THE LENGTH OF RECTANGLE = ");
x = sc.nextDouble();
System.out.println("ENTER THE BREADTH OF RECTANGLE = ");
y = sc.nextDouble();
}
public void compute_area()
{
double area;
area = (x * y);
System.out.println("THE AREA OF RECTANGLE IS = " + area);
}
}
class Circle extends Shape {
public void getdata()
{
Scanner sc = new Scanner(System.in);
System.out.println("ENTER THE RADIUS OF CIRCLE = ");
x = sc.nextDouble();
}
public void compute_area()
{
double area;
area = (3.14 * x * x);
System.out.println("THE AREA OF CIRCLE IS = " + area);
}}
class area {
public static void main(String args [])
{
Scanner sc = new Scanner(System.in);
int n;
do {
System.out.println("ENTER WHICH FIGURE AREA YOU WANT TO FINDOUT = ");
System.out.println("1.TRIANGLE");
System.out.println("2.CIRCLE");
System.out.println("3.RECTANGLE");
System.out.println("4.EXIT");
n = sc.nextInt();
switch (n)
{
case 1:
{
Triangle t = new Triangle();
t.getdata();
t.compute_area();
}break;
case 2:
{
Circle c = new Circle();
c.getdata();
c.compute_area();
}break;
case 3:
{
Rectangle r = new Rectangle();
r.getdata();
r.compute_area();
}break;
}
}while (n!=4);
}
}