/* File: Point.java - February 2019 */ package l01; /** * A basic Point class using double coordinates. * * @author Michael Albert * */ 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 this.x; } public double getY() { return this.y; } public Point clone() { return new Point(this.x, this.y); } public double distance(Point other) { double d2 = 0.0; d2 += (this.x - other.x)*(this.x - other.x); d2 += (this.y - other.y)*(this.y - other.y); return Math.sqrt(d2); } /* A toString() method is always useful even if only for debugging purposes. */ public String toString() { return "(" + x + "," + y + ")"; } public void move(double dx, double dy) { this.x += dx; this.y += dy; } }