JAVA编写Point类,要求: 具有属性:点的坐标(二维或三维) 具有方法:输出X坐标最大的点的坐标。 输出点关于原点的对称点。 分别输出两点间距离最近和最远的距离。
时间: 2023-04-12 14:00:36 浏览: 118
好的,以下是我对你的问题的回答:
对于JAVA编写Point类的要求,可以按照以下方式实现:
```
public class Point {
private double x;
private double y;
private double z;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public Point(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getZ() {
return z;
}
public Point getMaxXPoint(Point[] points) {
Point maxXPoint = points[0];
for (int i = 1; i < points.length; i++) {
if (points[i].getX() > maxXPoint.getX()) {
maxXPoint = points[i];
}
}
return maxXPoint;
}
public Point getSymmetricPoint() {
return new Point(-x, -y, -z);
}
public double getDistance(Point point) {
double dx = x - point.getX();
double dy = y - point.getY();
double dz = z - point.getZ();
return Math.sqrt(dx * dx + dy * dy + dz * dz);
}
public double getMinDistance(Point[] points) {
double minDistance = Double.MAX_VALUE;
for (int i = 0; i < points.length; i++) {
double distance = getDistance(points[i]);
if (distance < minDistance) {
minDistance = distance;
}
}
return minDistance;
}
public double getMaxDistance(Point[] points) {
double maxDistance = Double.MIN_VALUE;
for (int i = 0; i < points.length; i++) {
double distance = getDistance(points[i]);
if (distance > maxDistance) {
maxDistance = distance;
}
}
return maxDistance;
}
}
```
对于你的问题,我已经回答了,如果你有其他问题,可以继续提问。
阅读全文