-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.java
More file actions
68 lines (67 loc) · 1.49 KB
/
Copy pathShape.java
File metadata and controls
68 lines (67 loc) · 1.49 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
import java.util.*;
import java.lang.*;
abstract class Shape
{
abstract void numberofsides();
}
class Rectangle extends Shape
{
void numberofsides()
{
System.out.println("The number of sides in the rectangle is:4");
}
void printArea(int l,int b)
{
System.out.println("The area of the rectangle is:"+l*b);
}
}
class Triangle extends Shape
{
void numberofsides()
{
System.out.println("The number of sides in Triangle is:3");
}
void printArea(int l,double h)
{
System.out.println("The area of the triangle is:"+(0.5*l*h));
}
}
class Hexagon extends Shape
{
void numberofsides()
{
System.out.println("The number of sides in Hexagon is:6");
}
void printArea(int l)
{
System.out.println("The area of the hexagon is:"+((3*Math.sqrt(3)/2)*Math.pow(l,2)));
}
}
class Abshape
{
public static void main(String args[])
{
Scanner s1=new Scanner(System.in);
int a,b,c,sl;
double h;
Rectangle r1=new Rectangle();
Triangle t1=new Triangle();
Hexagon h1=new Hexagon();
r1.numberofsides();
t1.numberofsides();
h1.numberofsides();
System.out.println("Enter the length of the Rectangle:");
a=s1.nextInt();
System.out.println("Enter the breadth of the Rectangle:");
b=s1.nextInt();
System.out.println("Enter the height of the Triangle:");
h=s1.nextDouble();
System.out.println("Enter the length of the Triangle:");
c=s1.nextInt();
System.out.println("Enter the side length of the Hexagon:");
sl=s1.nextInt();
r1.printArea(a,b);
t1.printArea(c,h);
h1.printArea(sl);
}
}