/**
* @author: 袁
* @date: 2022-09-22 15:35
* @desc:分别编写两个类Point2D,Point3D来表示二维空间和三维空间的点,使之满足下列要求:
*/
class Point2D{
int x;
int y;
public Point2D(){
x = 0;
y = 0;
}
public Point2D(int x,int y)
{
this.x = x;
this.y = y;
}
public void offset(int a, int b){
x += a;
y += b;
}
}
class Point3D extends Point2D{
int x;
int y ;
int z;
public Point3D(int x,int y, int z){
this.x = x;
this.y = y;
this.z = z;
}
public Point3D(Point2D p, int z){
this.x = p.x;
this.y = p.y;
this.z = z;
}
public void offset(int a, int b,int c){
x += a;
y += b;
z += c;
}
public static void main(String[] args) {
Point2D p2d1 = new Point2D(1,1);
Point2D p2d2 = new Point2D(3,3);
double p2dis = Math.sqrt(Math.pow(p2d2.x - p2d1.x,2) + Math.pow(p2d2.y - p2d1.y,2));
System.out.println(p2dis);
Point3D p3d1 = new Point3D(1,1,1);
Point3D p3d2 = new Point3D(3,3,3);
double p3dis = Math.sqrt(Math.pow(p3d2.x - p3d1.x,2) + Math.pow(p3d2.y - p3d1.y,2)+Math.pow(p3d2.z - p3d1.z,2));
System.out.println(p3dis);
}
}
分别编写两个类Point2D,Point3D来表示二维空间和三维空间的点,并实现一下功能
于 2022-09-29 11:03:26 首次发布