forked from java-tester-x/JavaExercises4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyLineSub.java
More file actions
84 lines (72 loc) · 1.92 KB
/
MyLineSub.java
File metadata and controls
84 lines (72 loc) · 1.92 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package src;
public class MyLineSub extends MyPoint2 {
// A line needs two points: begin and end.
// The begin point is inherited from its superclass Point.
MyPoint2 end;
// Constructors
public MyLineSub (int beginX, int beginY, int endX, int endY) {
super(beginX, beginY);
this.end = new MyPoint2(endX, endY);
}
public MyLineSub (MyPoint2 begin, MyPoint2 end) {
super(begin.getX(), begin.getY());
this.end = end;
}
@Override
public String toString() {
return "Line: ("+getX()+", "+getY()+") - ("
+ end.getX()+", "+end.getY() +")";
}
public MyPoint2 getBegin() {
return new MyPoint2(getX(), getY());
}
public MyPoint2 getEnd() {
return end;
}
public void setBegin(MyPoint2 begin) {
this.setXY(begin.getX(), begin.getY());
}
public void setEnd(MyPoint2 end) {
this.end.setXY(end.getX(), end.getY());
}
public int getBeginX() {
return getX();
}
public int getBeginY() {
return getY();
}
public int getEndX() {
return end.getX();
}
public int getEndY() {
return end.getY();
}
public void setBeginX(int x) {
setX(x);
}
public void setBeginY(int y) {
setY(y);
}
public void setBeginXY(int x, int y) {
setXY(x, y);
}
public void setEndX(int x) {
end.setX(x);
}
public void setEndY(int y) {
end.setY(y);
}
public void setEndXY(int x , int y) {
end.setXY(x, y);
}
public int getLength() {
int xDiff = getEndX() - getBeginX();
int yDiff = getEndY() - getBeginY();
return (int) Math.sqrt(xDiff*xDiff + yDiff*yDiff);
}
public double getGradient() {
int xDiff = getEndX() - getBeginX();
int yDiff = getEndY() - getBeginY();
return Math.atan2(yDiff, xDiff);
}
}