回覆列表
  • 1 # 彩虹海呀

    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;

    }

    }

  • 中秋節和大豐收的關聯?
  • 私家車把行人撞出3米多遠,前擋風玻璃碎到穿孔,雨刷撞飛。肇事司機卻說車速只有40km /h,是不?