-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharea.java
More file actions
53 lines (48 loc) · 721 Bytes
/
area.java
File metadata and controls
53 lines (48 loc) · 721 Bytes
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
class shape
{
double l,b,h,area;
shape(double l)
{
this.l=l;
}
shape(double l,double h)
{
this.l=l;
this.h=h;
}
shape(double l,double b,double h)
{
this.l=l;
this.h=h;
this.b=b;
}
void calculate()
{
if(b==0)
{
if(h==0)
area=l*l;
area=0.5*l*h;
}
else
area=0.5*(l+b)*h;
}
void printData()
{
System.out.println("Area - "+area);
}
}
class area
{
public static void main(String args[])
{
shape triangle = new shape(4,9);
shape trapezium = new shape(4,8,6);
System.out.println("Triangle");
triangle.calculate();
triangle.printData();
System.out.println("Trapezium");
trapezium.calculate();
trapezium.printData();
}
}