-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLine.java
More file actions
61 lines (47 loc) · 1.18 KB
/
Line.java
File metadata and controls
61 lines (47 loc) · 1.18 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package labwork;
public class Line {
private Point start;
private Point end;
public Line(Point start, Point end) {
this.start = start;
this.end = end;
}
public Line(int x1 , int y1 , int x2 ,int y2 ){
//start = new Point(x1,y1);
//end = new Point(x2,y2);
//otherwise
start = new Point();
end = new Point();
start.setX(x1);
start.setY(y1);
end.setX(x2);
end.setY(y2);
}
public Point getStart() {
return start;
}
public void setStart(Point start) {
this.start = start;
}
public Point getEnd() {
return end;
}
public void setEnd(Point end) {
this.end = end;
}
public double getLength()
{
int dx = start.getX() - end.getX();
int dy = start.getY() - end.getY();
return Math.sqrt((dx*dx)+ (dy*dy));
}
/**
*
* @return
*/
@Override
public String toString()
{
return "Line [start(x: "+start.getX()+" , y: "+start.getY()+"), end(x: "+end.getX()+" , y: "+end.getY()+")]";
}
}