5、创建一个名称为CCCircle的类来表示平面坐标系上的圆形,要求圆心点用CCCircle的内部类Point表示,CCCircle类中包含求一点到圆心距离的方法public double distance(Piont p)。在main方法中实例化一个圆c((10,10),2),一个点p(5,5),再求p与c之间的关系。
public class CCCircle{
public double x;
public double y;
public static double r;
public CCCircle() {
x=0;
y=0;
r=0;
}
public CCCircle(double x,double y,double r) {
this.x=x;
this.y=y;
this.r=r;
}
public class Point{
public double x;
public double y;
public Point(double x,double y){
this.x=x;
this.y=y;
}
}
public double distance(Point p) {
return Math.sqrt((this.x-x)*(this.x-x)+(this.y-y)*(this.y-y));
}
public static void main(String[] args) {
CCCircle c=new CCCircle(10,10,2);
CCCircle.Point p=c.new Point(5,5);
if(c.distance(p)>r) {
System.out.println("点在圆外");
} else if(c.distance(p)==r) {
System.out.println("点在圆上");
} else {
System.out.println("点在圆内");}