Java
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,42 @@
|
||||
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 == s2.start && this.end == s2.end;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
public class TestSegment {
|
||||
public static void main(String[] args) {
|
||||
Segment s = new Segment(0, 10, 10, 0);
|
||||
Segment s2 = new Segment(0, 10, 10, 0);
|
||||
|
||||
System.out.println(s.equals(s2));
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user