-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClient.java
More file actions
67 lines (63 loc) · 1.68 KB
/
Client.java
File metadata and controls
67 lines (63 loc) · 1.68 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
package own;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Client {
private static Point[] readPoints() {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Introduce the number of points");
int n = 0;
try {
n = Integer.parseInt(br.readLine());
} catch (IOException e) {
System.out.println("Please introduce a natural number.");
System.exit(0);
}
Point[] points = new Point[n];
for (int i = 0; i < n; i++) {
System.out.println("Introduce the next point");
double x = 0;
double y = 0;
boolean try_again = true;
int tries = 0;
while (try_again && tries < 5)
try {
System.out.println("x=");
x = Double.parseDouble(br.readLine());
try_again = false;
} catch (IOException e) {
try_again = true;
tries++;
System.out.println("Invalid input, try again");
if (tries == 5) {
System.out
.println("You are unable to pass in a valid coordinate");
System.exit(0);
}
}
try_again = true;
tries = 0;
while (try_again && tries < 5)
try {
System.out.println("y=");
y = Double.parseDouble(br.readLine());
try_again = false;
} catch (IOException e) {
try_again = true;
tries++;
System.out.println("Invalid input, try again");
if (tries == 5) {
System.out
.println("You are unable to pass in a valid coordinate");
System.exit(0);
}
}
points[i] = new Point(x, y);
}
return points;
}
public static void main(String[] args) {
Point[] points = readPoints();
System.out.println(new GreatestDistance(points).getMaximumDistance());
}
}