大大们写一下,注释啊,求class Point {double x,y,z;Point(double _x,double _y,double _z) {x = _x;y = _y;z = _z;}void setX(double _x) {x = _x;}double getDistance(Point p) {return (x - p.x)*(x - p.x) + (y - p.y)*(y - p.y) + (z - p.z)*(z - p.z);}}

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 23:50:46
大大们写一下,注释啊,求class Point {double x,y,z;Point(double _x,double _y,double _z) {x = _x;y = _y;z = _z;}void setX(double _x) {x = _x;}double getDistance(Point p) {return (x - p.x)*(x - p.x) + (y - p.y)*(y - p.y) + (z - p.z)*(z - p.z);}}
xUO@Wc;k4|?c̀,Y%K! !AD2ncݕFè_Lww޽{CQDA1eiBdF)x.9)Y#:.&}k8;(MbȀd4ɪϪcL~L2< )O'yTY̆,P&ܤ!kWMR"3dr{;!]$% 2'hIy6Ml΂_w=IZooKwo4D`ArF?nN-$xīYft-O[!

大大们写一下,注释啊,求class Point {double x,y,z;Point(double _x,double _y,double _z) {x = _x;y = _y;z = _z;}void setX(double _x) {x = _x;}double getDistance(Point p) {return (x - p.x)*(x - p.x) + (y - p.y)*(y - p.y) + (z - p.z)*(z - p.z);}}
大大们写一下,注释啊,求
class Point {
double x,y,z;
Point(double _x,double _y,double _z) {
x = _x;
y = _y;
z = _z;
}
void setX(double _x) {
x = _x;
}
double getDistance(Point p) {
return (x - p.x)*(x - p.x) + (y - p.y)*(y - p.y) + (z - p.z)*(z - p.z);
}
}
public class TestPoint {
public static void main(String[] args) {
Point p = new Point(1.0,2.0,3.0);
Point p1 = new Point(0.0,0.0,0.0);
System.out.println(p.getDistance(p1));
p.setX(5.0);
System.out.println(p.getDistance(new Point(1.0,1.0,1.0)));
}
}

大大们写一下,注释啊,求class Point {double x,y,z;Point(double _x,double _y,double _z) {x = _x;y = _y;z = _z;}void setX(double _x) {x = _x;}double getDistance(Point p) {return (x - p.x)*(x - p.x) + (y - p.y)*(y - p.y) + (z - p.z)*(z - p.z);}}
/**
* Point类用于创建三维空间中的一个点
*
*/
class Point {
double x,y,z; // x、y、z轴上的坐标
/**
* 构造方法,根据指定的参数创建一个三维空间中的点
* @param _x x坐标
* @param _y y坐标
* @param _z z坐标
*/
Point(double _x,double _y,double _z) {
x = _x;
y = _y;
z = _z;
}
/**
* 设置x坐标
* @param _x
*/
void setX(double _x) {
x = _x;
}
/**
* 计算当前点与指定点之间的距离的平方
* @param p
* @return
*/
double getDistance(Point p) {
return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y) + (z - p.z)
* (z - p.z);
}
}
/**
* 测试类
*
*/
public class TestPoint {
public static void main(String[] args) {
Point p = new Point(1.0,2.0,3.0);// 创建一个点,x坐标1.0,y坐标2.0,z坐标3.0
Point p1 = new Point(0.0,0.0,0.0);// 创建一个点,坐标0,0,0,即原点
System.out.println(p.getDistance(p1));// 计算p点与原点p1之间距离的平方并打印.注意getDistance方法计算的是距离的平方,而非距离,若要取得两点距离需要进行一次开方
p.setX(5.0);// 将p点的x坐标设为5.0
System.out.println(p.getDistance(new Point(1.0,1.0,1.0)));// 计算p点与点(1,1,1)之间距离的平方并打印
}
}