APL/APL2.1/TP04/Segment/Segment.java
2022-03-07 17:26:31 +01:00

42 lines
847 B
Java

import java.awt.Point;
public class Segment {
private Point start;
private Point end;
public Segment(Point p1, Point p2) {
start = p1;
end = p2;
}
public Segment(int x1, int y1, int x2, int y2) {
start = new Point(x1, y1);
end = new Point(x2, y2);
}
public double length() {
return Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));
}
public void setStart(Point p) {
start = p;
}
public void setStart(int x, int y) {
start.x = x;
start.y = y;
}
public void setEnd(Point p) {
end = p;
}
public void setEnd(int x, int y) {
end.x = x;
end.y = y;
}
public boolean equals(Segment s2) {
return (this.start.equals(s2.start) && this.end.equals(s2.end));
}
}