import java.io.*;
import java.text.*;
class fig
{
double dim1,dim2;
fig(double d1,double d2)
{
dim1=d1;
dim2=d2;
}
double area()
{
return 0;
}
}
class rec extends fig
{
rec(double d1,double d2)
{
super(d1,d2);
}
double area()
{
double r=dim1*dim2;
return r;
}
}
class tri extends fig
{
tri(double d1,double d2)
{
super(d1,d2);
}
double area();
{
double r1=(0.5*dim1*dim2);
return r1;
}
}
class Ddemo
{
public static void main(String args[])throws IOException,ParseException
{
double l,b,b1,h,res,res1;
DataInputStream x=new DataInputStream(System.in);
DecimalFormat df=new DecimalFormat("###.##");
System.out.print("Enter the length=");
l=Double.parseDouble(x.readLine());
System.out.print("Enter the breadth=");
b=Double.parseDouble(x.readLine());
System.out.print("Enter the height=");
h=Double.parseDouble(x.readLine());
System.out.print("Enter the breadth=");
b1=Double.parseDouble(x.readLine());
fig ref;
rec R=new rec(l,b);
ref=R;
res=ref.area();
res=df.parse(df.format(res)).doubleValue();
System.out.println("RESULT \n---------");
System.out.println("Area of \"Rectangle\"="+res);
tri T=new tri(b1,h);
ref=T;
res1=ref.area();
res1=df.parse(df.format(res1)).doubleValue();
System.out.println("Area of \"Triangle\"="+res1);
}
}
-------------
OUTPUT:
-------------
Enter the Length
10.7
Enter the breadth
20.5
Enter the height
15.5
Enter the breadth
11.5
Result:
--------
Area of "Rectangle"=219.35
Area of "Triangle"=89.12
import java.text.*;
class fig
{
double dim1,dim2;
fig(double d1,double d2)
{
dim1=d1;
dim2=d2;
}
double area()
{
return 0;
}
}
class rec extends fig
{
rec(double d1,double d2)
{
super(d1,d2);
}
double area()
{
double r=dim1*dim2;
return r;
}
}
class tri extends fig
{
tri(double d1,double d2)
{
super(d1,d2);
}
double area();
{
double r1=(0.5*dim1*dim2);
return r1;
}
}
class Ddemo
{
public static void main(String args[])throws IOException,ParseException
{
double l,b,b1,h,res,res1;
DataInputStream x=new DataInputStream(System.in);
DecimalFormat df=new DecimalFormat("###.##");
System.out.print("Enter the length=");
l=Double.parseDouble(x.readLine());
System.out.print("Enter the breadth=");
b=Double.parseDouble(x.readLine());
System.out.print("Enter the height=");
h=Double.parseDouble(x.readLine());
System.out.print("Enter the breadth=");
b1=Double.parseDouble(x.readLine());
fig ref;
rec R=new rec(l,b);
ref=R;
res=ref.area();
res=df.parse(df.format(res)).doubleValue();
System.out.println("RESULT \n---------");
System.out.println("Area of \"Rectangle\"="+res);
tri T=new tri(b1,h);
ref=T;
res1=ref.area();
res1=df.parse(df.format(res1)).doubleValue();
System.out.println("Area of \"Triangle\"="+res1);
}
}
-------------
OUTPUT:
-------------
Enter the Length
10.7
Enter the breadth
20.5
Enter the height
15.5
Enter the breadth
11.5
Result:
--------
Area of "Rectangle"=219.35
Area of "Triangle"=89.12
0 comments:
Post a Comment