-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArea1.java
More file actions
43 lines (38 loc) · 999 Bytes
/
Area1.java
File metadata and controls
43 lines (38 loc) · 999 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
import java.io.*;
import java.util.*;
interface AreaI{
void find_area();
}
class Triangle1 implements AreaI{
double dim1,dim2;
public void find_area()
{
System.out.println("Area of triangle="+(0.5*dim1*dim2));
}
}
class Rectangle1 implements AreaI{
double dim1,dim2;
public void find_area()
{
System.out.println("Area of rectangle="+(dim1*dim2));
}
}
public class Area1 {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
AreaI f;
Triangle1 t=new Triangle1();
Rectangle1 r=new Rectangle1();
System.out.println("Enter two dimentions");
t.dim1=Double.parseDouble(br.readLine());
t.dim2=Double.parseDouble(br.readLine());
f=t;
f.find_area();
System.out.println("Enter two dimentions");
r.dim1=Double.parseDouble(br.readLine());
r.dim2=Double.parseDouble(br.readLine());
f=r;
f.find_area();
}
}