国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

java中的一個MyPoint方法

2019-11-17 04:03:39
字體:
來源:轉載
供稿:網友
設計一個Circle類,其屬性為原點(類型為類MyPoint)和半徑,并為此類編寫以下三個方法:

一、計算圓的面積的calArea()方法;

二、計算周長的calLength()方法;

三、boolean inCircle(MyPoint mp)方法,功能是測試作為參數的某個點是否在當前對象圓內(圓內,包括圓上返回true,在圓外返回false)。

程序:

class MyPoint{
  PRivate int x,y;
  public void setX(int x){
   this.x=x;
  }
  public int getX(){
  return this.x;
  }
  public void setY(int y){
   this.y=y;
  }
  public int getY(){
  return this.y;
  }
  public String toString(){
   String str="("+this.x+","+this.y+")";
   return str;
  }
}
class Circle {
private MyPoint myPoint=null;
private double radius=0.0;
public Circle(MyPoint myPoint,int radius){
this.myPoint=myPoint;
this.radius=radius;
}
public double calArea(){
  return Math.PI*radius*radius;
}
public double calLength(){
  return 2*Math.PI*radius;
}
public boolean inCircle(MyPoint mp){
  double a=Math.sqrt(Math.pow(mp.getX()-myPoint.getY(),2)+Math.pow(mp.getY()-myPoint.getY(),2));
if(a>radius){
return false;
}
return true;
}
}

public class T14{
public static void main(String args[]){
  MyPoint mp=new MyPoint();
  mp.setX(0);
  mp.setY(0);
  Circle c=new Circle(mp,5);
  double area=c.calArea();
  double length=c.calLength();
  MyPoint mp2=new MyPoint();
  mp2.setX(3);
  mp2.setY(3);
  boolean in=c.inCircle(mp2);
  System.out.println("area="+area+",length="+length+",inCircle="+in);

}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 虞城县| 常德市| 巴林左旗| 大丰市| 玛多县| 济阳县| 新营市| 尤溪县| 荆门市| 府谷县| 曲麻莱县| 井研县| 高青县| 应用必备| 曲麻莱县| 周口市| 棋牌| 耒阳市| 阜新市| 青川县| 吉木乃县| 济阳县| 慈利县| 合作市| 丹阳市| 浠水县| 肇庆市| 井研县| 广元市| 土默特右旗| 平安县| 饶平县| 湘阴县| 河间市| 隆尧县| 五指山市| 长垣县| 武安市| 嘉定区| 德安县| 汤阴县|