java Point2D Point3D 1.分别编写两个类Point2D,Point3D来表示二维空间和三维空间的点,使之满足下列要求:(1)Point2D有两个整型成员变量x,y(分别为二维空间的X,Y方向坐标),Point2D的构造方法要实现对其成员变量x,y的初始化。(2)Point2D有一个void型成员方法offset(inta,intb),它可以实现Point2D的...
Double x2 = input.nextDouble(); Double y2 = input.nextDouble(); Point2D p1 = new Point2D(x1,y1); Point2D p2 = new Point2D(x2,y2); System.out.println("point1 is "+ p1.toString()); System.out.println("point2 is "+ p2.toString()); System.out.println("The distance between ...
Point2D是一个抽象类,不能实例化,可以试试new Point(x1,y1),但是Point的构造方法接收的是int不是double,可以试试new Point2D.Double(x1,y1)。Point2D.Double的构造方法可以接收double类型
Point2D p2 = new Point2D(2,2);Point3D p3 = new Point3D(4,4,4);p3.offset(4,2,3);//可以进行移动 Point3D p4 = new Point3D(5,5,5);System.out.println("p1和p2之间的距离为:");System.out.println(new Point2D().distan(p1,p2));System.out.println("p3和p4间的距离为...
java.lang.Object └java.awt.geom.Point2D 所有已实现的接口: Cloneable 直接已知子类: Point, Point2D.Double, Point2D.Float public abstract cl…
}publicdoubledistanceOfTwoPoints(Point point){returnMath.sqrt((this.x - point.x) * (this.x - point.x) + (this.y - point.y) * (this.y -point.y)); }publicvoidsetX(doublex) {this.x =x; }publicvoidsetY(doubley) {this.y =y; ...
public Point3D(int x, int y, int z){ super(x, y);this.z = z;} public Point3D(){ } public Point3D(Point2D p, int z){ super(p.x, p.y);this.z = z;} public void offset(int a, int b,int c){ x = a;y = b;z = c;this.x = this.x + 1;this.y = ...
9.15 如何创建一个 Point2D? 假设pi 和 p2 是 Point2D 的两个实例,如何获得两点之间的距离? public class Test { public static void main(String[] args) { Point2D p1 = new Point(1,0); Point2D p2 = new Point(0,1); System.out.println(p1.distance(p2)); ...