-
Notifications
You must be signed in to change notification settings - Fork 0
/
chit24.java
50 lines (42 loc) · 1.18 KB
/
chit24.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
//~Interface Area is having method calculateArea(). Calculate the area for the following classes: Square, Circle, Triangle, Rectangle
interface Area {
void calculateArea();
}
class Square implements Area {
public void calculateArea() {
double l = 6.8;
System.out.println("Area of square is: " + l * l);
}
}
class Circle implements Area {
public void calculateArea() {
double r = 6.8;
System.out.println("Area of Circle is: " + 3.14 * r * r);
}
}
class Triangle implements Area {
public void calculateArea() {
double h = 6.8;
double b = 6.8;
System.out.println("Area of triangle is: " + .5 * (h * b));
}
}
class Rectangle implements Area {
public void calculateArea() {
double l = 6.8;
double w = 6.8;
System.out.println("Area of rectangle is: " + l * w);
}
}
public class chit24 {
public static void main(String[] args) {
Square s = new Square();
Circle c = new Circle();
Triangle t = new Triangle();
Rectangle r = new Rectangle();
s.calculateArea();
c.calculateArea();
t.calculateArea();
r.calculateArea();
}
}