-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathPolyLine.java
More file actions
37 lines (29 loc) · 768 Bytes
/
PolyLine.java
File metadata and controls
37 lines (29 loc) · 768 Bytes
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
package src.ex8;
import java.util.List;
import java.util.ArrayList;
public class PolyLine {
private List<Point> points = new ArrayList<Point>();
public PolyLine() { } // default constructor
public PolyLine(List<Point> points) {
this.points = points;
}
public void appendPoint(Point point) {
points.add(point);
}
public void appendPoint(int x, int y) {
points.add(new Point(x, y));
}
public String toString()
{
StringBuilder sb = new StringBuilder();
int i = 0;
for (Point aPoint : points) {
if (i != 0) {
sb.append(", ");
}
sb.append(aPoint.toString());
i++;
}
return sb.toString();
}
}