06-04-2011, 01:17 PM
Code:
import java.io.*;
class Figure
{
double x,y;
Figure(double l, double m)
{
x=l;
y=m;
}
}
class Rectangle extends Figure
{
Rectangle(double l, double m)
{
super(l,m);
}
double area()
{
return(x*y);
}
}
class Circle extends Figure
{
final float pi=3.14f;
Circle(double l,double m)
{
super(l,m);
}
double area()
{
return(pi*x);
}
}
class Triangle extends Figure
{
Triangle(double d1,double d2)
{
super(d1,d2);
}
double area()
{
return((x*y)/2);
}
}
class Over
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Figure f;
System.out.println("enter the length and breadth");
Rectangle r=new Rectangle(Integer.parseInt(br.readLine()), Integer.parseInt(br.readLine()));
f=r;
System.out.println("the area of the rectangle is"+r.area());
System.out.println("enter the radius" );
Circle ci=new Circle(Integer.parseInt(br.readLine()),Integer.parseInt(br.readLine()));
f=ci;
System.out.println("The area of circle is"+ci.area());
System.out.println("Enter the breadth and height");
Triangle t=new Triangle(Integer.parseInt(br.readLine()),Integer.parseInt(br.readLine()));
f=t;
System.out.println("the area of triangle is "+t.area());
}
}
OUTPUT
E:\111msc\java>java Over
enter the length and breadth
2
3
the area of the rectangle is6.0
enter the radius
2
1
The area of circle is6.28000020980835
Enter the breadth and height
3
4
the area of triangle is 6.0