Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package po2;
- import java.lang.Math;
- public class Point implements Comparable{
- private int coordX, coordY;
- public Point(int coordX, int coordY) {
- super();
- this.coordX = coordX;
- this.coordY = coordY;
- }
- @Override
- public String toString() {
- return "Point [coordX=" + coordX + ", coordY=" + coordY + "]";
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + coordX;
- result = prime * result + coordY;
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Point other = (Point) obj;
- if (coordX != other.coordX)
- return false;
- if (coordY != other.coordY)
- return false;
- return true;
- }
- public int getCoordX() {
- return coordX;
- }
- public void setCoordX(int coordX) {
- this.coordX = coordX;
- }
- public int getCoordY() {
- return coordY;
- }
- public void setCoordY(int coordY) {
- this.coordY = coordY;
- }
- @Override
- public int compareTo(Object o) {
- if( Math.abs(this.getCoordX()) + Math.abs(this.getCoordY()) > Math.abs(((Point) o).getCoordX()) + Math.abs(((Point) o).getCoordY())){
- return 1;
- }else if( Math.abs(this.getCoordX()) + Math.abs(this.getCoordY()) < Math.abs(((Point) o).getCoordX()) + Math.abs(((Point) o).getCoordY())){
- return -1;
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement