-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArea.java
More file actions
40 lines (36 loc) · 874 Bytes
/
Area.java
File metadata and controls
40 lines (36 loc) · 874 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
import java.util.*;
class Figure{
double dim1,dim2;
public void area() {System.out.println("Not defined");}
}
class Triangle extends Figure{
public void area() {
double temp=0.5*dim1*dim2;
System.out.println("Area of Triangle="+temp);
}
}
class Rectangle extends Figure{
public void area() {
double temp=(dim1*dim2);
System.out.println("Area of Rectangle="+temp);
}
}
public class Area {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
Figure f;
Triangle t=new Triangle();
Rectangle r=new Rectangle();
System.out.println("Enter two dimentions");
t.dim1=sc.nextDouble();
t.dim2=sc.nextDouble();
f=t;
f.area();
System.out.println("Enter two dimentions");
r.dim1=sc.nextDouble();
r.dim2=sc.nextDouble();
f=r;
f.area();
}
}