免费源代码下载整理 - 云代码空间
—— 每天更新整理各种PHP、JSP、ASP源代码,敬请关注我的微博 http://weibo.com/freecodedownload
public class Circle2D{ private double x; private double y; private double radius; public static final double PI=3.14; //getter public double getX(){ return this.x; } public double getY(){ return this.y; } public double getRadius(){ return this.radius; } //constructor public Circle2D(){ this.x=0; this.y=0; this.radius=1; } public Circle2D(double x,double y,double radius){ this.x=x; this.y=y; this.radius=radius; } //Method public double getArea(){ return PI*radius*radius; } public double getPerimeter(){ return 2*PI*radius; } private double getDistance(doublex,doubley){ return Math.sqrt((this.x-x)*(this.x-x)+(this.y-y)*(this.y-y));; } public boolean contains(double x,double y){ if(getDistance(x,y)<radius) return true; return false; } public boolean contains(Circle2D circle){ double dis=getDistance(circle.getX(),circle.getY()); if(dis+circle.getRadius()<this.radius) return true; return false; } public boolean overlaps(Circle2D circle){ dobule dis=getDistance(circle.getX(),circle.getY()); if((dis-circle.getRadius())<this.radius&&(dis+circle.getRadius())>this.radius) return true; return false; } }