
package homework8;

public class MyPoint implements Comparable<MyPoint>{

    private int x;
    private int y;

    public MyPoint(int x1, int y1) {
        x = x1;
        y = y1;
    }

    public boolean equals(Object p) {
        MyPoint p1;
        try {p1 = (MyPoint) p;}
        catch (ClassCastException ex) {return false;}
        return (x == p1.x) && (y == p1.y);
    }

    public int hashCode() {
        return x + y;
    }

    public int compareTo(MyPoint p) {
        if ( x < p.x )
            return -1;
        if (x > p.x)
            return +1;
        if (y < p.y )
            return - 1;
        if (y > p.y )
            return +1;
        return 0;
    }

}
