Last active
February 9, 2018 21:25
-
-
Save bandrzejczak/cc5eb6125b9235f4e4e820f46b19e67d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Point { | |
private int x; | |
private int y; | |
public Point(int x, int y) { | |
setX(x); | |
setY(y); | |
} | |
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; | |
} | |
@Override | |
public boolean equals(Object other) { | |
if (other instanceof Point) { | |
Point otherPoint = (Point) other; | |
return otherPoint.getX() == getX() && | |
otherPoint.getY() == getY(); | |
} else { | |
return false; | |
} | |
} | |
@Override | |
public int hashCode() { | |
return (new Integer[] {getX(), getY()}).hashCode(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment