public class Circle {
private double radius;
Circle(double radius){
this.radius=radius;
}
public double getRadius(){
return radius;
}
public void setRadius(){
this.radius=radius;
}
public double getArea(){
return 3.14*radius*radius;
}
public double getPerimeter(){
return 2*3.14*radius;
}
public boolean equals(Object obj){
if(this.radius==((Circle)obj).getRadius()){
return true;
}
else{
return false;
}
}
}
class Column extends Circle{
private double h;
Column(double h,double radius){
super(radius);
this.h=h;
}
public double getH(){
return h;
}
public void setH(){
this.h=h;
}
public double getArea(){
return 2*super.getArea()+super.getPerimeter()*h;
}
public double getVolume(){
return super.getArea()*h;
}
public String toString(){
return "半径:"+this.getRadius()+"高:"+this.getH();
}
public boolean equals(Object obj){
if(this.h==((Column)obj).h && super.getRadius()==((Column)obj).getRadius()){
return true;
}
else{
return false;
}
}
}
public class ColumnTest {
public static void main(String[] args) {
Circle a=new Circle(5);
Circle a2=new Circle(5);
a.equals(a2);
if(a.equals(a2)==true){
System.out.println("两个圆相等。");
}
else{
System.out.println("两个圆不相等。");
}
Column b=new Column(10,5);
System.out.println("体积:"+b.getVolume()+"表面积:"+b.getArea());
Column b2=new Column(3,4);
b.equals(b2);
if(b.equals(b2)==true){
System.out.println("两个圆柱相等。");
}
else{
System.out.println("两个圆柱不相等。");
}
}
}