-
Notifications
You must be signed in to change notification settings - Fork 0
/
Point.java
56 lines (49 loc) · 1.64 KB
/
Point.java
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
import java.util.*;
import java.io.*;
public class Point {
private ArrayList<PointPosition> positions = new ArrayList<>();
private InputStream is = MainPoint.class.getResourceAsStream("/coordinates.txt");
private int x, y;
private int centerX, centerY;
public Point() {
createPoints();
}
private void createPoints() {
String line = null;
try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
while ((line = br.readLine()) != null) {
String[] arr =line.split(" ");
x = Integer.parseInt(arr[0]);
y = Integer.parseInt(arr[1]);
positions.add(new PointPosition(x, y));
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void findPointsAndCenter(int radius) {
int N = 0;
for (PointPosition position : positions) {
if (position.getX() > radius || position.getY() > radius) {
System.out.print("");
} else {
System.out.println("Point (" + position.getX() + ", " + position.getY() + ")" + " belongs to object");
centerX += position.getX();
centerY += position.getY();
N++;
}
}
centerX = centerX/N;
centerY = centerY/N;
System.out.println("Coordinates of center: (" + centerX + ", " + centerY + ")");
}
public ArrayList<PointPosition> getPositions() {
return positions;
}
public int getCenterX() {
return centerX;
}
public int getCenterY() {
return centerY;
}
}