以Point类为基础,定义一个平面中的Circle类:
1、 编写一个无参的构造函数;
2、 编写一个有参的构造函数;
3、 在主函数中调用无参的构造函数生成圆的实例c1,调用有参的构造函数生成圆的实例c2,调用实例方法判断c1和c2是否相重叠。
##
package test2;
public class Point {
double x;
double y;
double radius;
Point(){
x=1.0;
y=1.0;
radius=1.0;
}
Point(double xx, double yy,double rr){
x = xx;
y = yy;
radius=rr;
}
void Overlap(Point p2)
{
if(x==p2.x && y==p2.y && radius==p2.radius)
{
System.out.println("两个圆重叠");
}
else
System.out.println("两个圆不重叠");
}
}
package test2;
import java.util.*;
public class Circle {
/*public Circle() {
// TODO Auto-generated constructor stub
}*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Point p1=new Point();
double a,b,c;
Scanner input =new Scanner(System.in);
System.out.println("请输入c2的坐标和半径:");
a=input.nextDouble();
b=input.nextDouble();
c=input.nextDouble();
Point p2=new Point(a,b,c);
p1.Overlap(p2);
}
}