题目相对简单:
package naizi;
public class Circle {
//私有成员及构造方法
private Point center;
private int r;
Circle(int rr,Point Cc){
this.r=rr;
this.center=Cc;
}
public void showInfo(){ //打印信息
System.out.println("center=("+center.getx()+","+center.gety()+");r="+r+";");
}
public static void main(String args[]){
Point p=new Point(10,20);
Circle c=new Circle(5,p);
p.showInfo();
c.showInfo();
}
}
//圆心坐标的点类
class Point{
private int x,y;
Point(int x,int y){
this.x=x;
this.y=y;
}
public int getx() {
return x;
}
public int gety() {
return y;
}
public void showInfo(){
System.out.println("x="+this.x+";"+"y="+this.y+";");
}
}
测试如图: