编写Java程序,设计Circle类和Point类,Point类表示平面直角坐标系中的几何点,具有横坐标x和纵坐标y两个属性;Circle类具有以下属性和方法: A.center-圆心 B.radius-半径 对属性进行封装;--- 构造方法 A.无参构造方法:对内部字段进行初始化 B.带有两个参数的构造方法 实例方法: A.getLength():求圆周长 B.getArea(): 求圆面积 静态方法: A.distance(Circle c1,Circle c2): 求两个圆的距离 B.isCrossed(Circle c1,Circle c2): 判断两个圆是否相交
时间: 2024-03-02 16:54:17 浏览: 46
好的,以下是Java代码实现:
Point类:
```java
public class Point {
private double x;
private double y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
}
```
Circle类:
```java
public class Circle {
private Point center;
private double radius;
public Circle() {
center = new Point(0, 0);
radius = 0;
}
public Circle(Point center, double radius) {
this.center = center;
this.radius = radius;
}
public Point getCenter() {
return center;
}
public double getRadius() {
return radius;
}
public double getLength() {
return 2 * Math.PI * radius;
}
public double getArea() {
return Math.PI * radius * radius;
}
public static double distance(Circle c1, Circle c2) {
double dx = c1.getCenter().getX() - c2.getCenter().getX();
double dy = c1.getCenter().getY() - c2.getCenter().getY();
double d = Math.sqrt(dx * dx + dy * dy);
return d - c1.getRadius() - c2.getRadius();
}
public static boolean isCrossed(Circle c1, Circle c2) {
double dx = c1.getCenter().getX() - c2.getCenter().getX();
double dy = c1.getCenter().getY() - c2.getCenter().getY();
double d = Math.sqrt(dx * dx + dy * dy);
return d <= c1.getRadius() + c2.getRadius();
}
}
```
阅读全文