java設計并實現一個類?
public class Circular{
//圓心x
private double centerx;
//圓心y
private double centery;
//半徑
private double radius;
private double PI =3.14;
//set get 方法
public void setCenterx(double centerx){
this.centerx = centerx;
}
public double getCenterx(){
return centerx;
}
public void setCentery(double centery){
this.centery = centery;
}
public double getCentery(){
return centery;
}
public void setRadius(double radius){
this.radius = radius;
}
public double getRadius(){
return radius;
}
//計算面積
public double getArea(){
return PI*radius*radius;
}
//計算周長
public double getRound(){
return 2*PI*radius;
}
//是否相交
public boolean isTouch(double otherx,double othery,double otherRadius){
double x = this.centerx-otherx;
double y = this.centery-othery;
double s = Math.pow(x,2)+Math.pow(y,2);
//兩個圓心距離
double d = Math.pow(s,0.5);
//兩個圓半徑之和
double sumR = radius + otherRadius;
return sumR >= d?true:false;
}
}