Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Point {
- /**
- * X coordinate.
- */
- private int x;
- /**
- * Y coordinate.
- */
- private int y;
- /**
- * Default constructor.
- */
- public Point() {
- this(0, 0);
- }
- /**
- * Constructor.
- * @param x Coordinate for x-axis.
- * @param y Coordinate for y-axis.
- */
- public Point(int x, int y) {
- this.x = x;
- this.y = y;
- }
- /**
- * Copy constructor.
- * @param p Object to copy.
- */
- public Point(Point p) {
- this(p.x, p.y);
- }
- /**
- * @return the distance of p from this.
- */
- public double distanceFrom(Point p) {
- int dx = this.x - p.x;
- int dy = this.y - p.y;
- return Math.sqrt(dx*dx + dy*dy);
- }
- /**
- * @param point to compare to.
- * @return true if the ginen point equals this point.
- */
- public boolean equals(Point p) {
- return this.x == p.x && this.y == p.y;
- }
- public String toString() {
- return String.format("(%d, %d)", getX(), getY());
- }
- public int getX() {
- return x;
- }
- public void setX(int x) {
- this.x = x;
- }
- public int getY() {
- return y;
- }
- public void setY(int y) {
- this.y = y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement