aboutsummaryrefslogtreecommitdiff
path: root/semestre 4/java/tme/tp3/Point.java
blob: 1fdf9fa312967b2833eaa5a55091d2411847eabf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class Point {
    private int posX, posY;

    public Point(int x, int y) {
        posX = x;
        posY = y;
    }

    public Point() {
        posX = (int) (Math.random()*10);
        posY = (int) (Math.random()*10);
    }

    public Point(Point p) {
        posX = p.posX;
        posY = p.posY;
    }

    public String toString() {
        return String.format("(%d,%d)", posX, posY);
    }

    public double distance(Point p) {
        return Math.sqrt(
                (p.posX - posX)*(p.posX - posX) + (p.posY - posY)*(p.posY - posY)
        );
    }

    public void deplaceToi(int x, int y) {
        posX = x;
        posY = y;
    }

    public boolean equals(Object o) {
        if (!(o instanceof final Point p)) return false;
        return posX == p.posX && posY == p.posY;
    }
}