//Msv:581597
//Lớp:K58QLTT
Đề 03;
public class
Circle
{
private double radius;
private String color;
public Circle()
{
this.radius=1.0;
}
public Circle(double radius)
{
this.radius=radius;
}
public double getRadius()
{
return this.radius;
}
public double getArea()
{
return Math.PI*this.radius*this.radius;
}
}
//----------------------------------------------------
public class Cylinder extends Circle
{
private
double height;
//contructor
public
Cylinder()
{
this.height=1.0;
}
public
Cylinder(double radius)
{
super(radius);
this.height=1.0;
}
public
Cylinder(double radius,double height)
{
super(radius);
this.height=height;
}
public
double getHeight()
{
return
this.height;
}
//ham tinh
the tich
public
double getVolume()
{
return
super.getArea()*this.height;
}
//overide
equals
public
boolean equals(Object obj)
{
Cylinder
tg=(Cylinder)obj;
if(this.getRadius()==tg.getRadius()&&this.height==tg.getHeight())
{
return true;
}
return
false;
}
}
//---------------------------------------------------------
public class Test
{
public static
void main(String[] args)
{
//su dung ham tao Cylinder();
Cylinder
ht1=new Cylinder();
System.out.println("Ban kinh :"+ht1.getRadius());
System.out.println("Chieu cao: "+ht1.getHeight());
System.out.println("Dien tich mot mat: "+ht1.getArea());
System.out.println("The tich:
"+ht1.getVolume());
//su dung
ham tao Cylinder(5.0,2.0);
Cylinder
ht2=new Cylinder(5.0,2.0);
System.out.println("Ban kinh :"+ht2.getRadius());
System.out.println("Chieu cao: "+ht2.getHeight());
System.out.println("Dien tich mot mat: "+ht2.getArea());
System.out.println("The tich: "+ht2.getVolume());
}
}
0 comments:
Post a Comment