-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemointerface.java
More file actions
67 lines (56 loc) · 1.45 KB
/
demointerface.java
File metadata and controls
67 lines (56 loc) · 1.45 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
import java.util.Scanner;
interface a {
void input();
void display();
}
class triangle implements a {
int a, b, area;
public void input() {
System.out.println("Enter a and b value:");
Scanner z = new Scanner(System.in);
a = z.nextInt();
b = z.nextInt();
}
public void display() {
area = (int)(0.5 * a * b);
System.out.println("Area of triangle is: " + area);
}
}
class rectangle implements a {
int l, w, area;
public void input() {
System.out.println("Enter l and w value:");
Scanner z = new Scanner(System.in);
l = z.nextInt();
w = z.nextInt();
}
public void display() {
area = l * w;
System.out.println("Area of rectangle is: " + area);
}
}
class cube implements a {
int c, area;
public void input() {
System.out.println("Enter c value:");
Scanner z = new Scanner(System.in);
c = z.nextInt();
}
public void display() {
area = 6 * c * c;
System.out.println("Area of cube is: " + area);
}
}
public class demointerface {
public static void main(String[] args) {
triangle t = new triangle();
rectangle r = new rectangle();
cube e = new cube();
t.input();
t.display();
r.input();
r.display();
e.input();
e.display();
}
}