-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoordinates.java
More file actions
56 lines (47 loc) · 1.42 KB
/
Coordinates.java
File metadata and controls
56 lines (47 loc) · 1.42 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
import java.util.Scanner;
public class Coordinates {
private Float x; //Поле не может быть null
private Integer y; //Поле не может быть null
public Coordinates(Float x, Integer y) {
this.x = x;
this.y = y;
}
public static Coordinates insert() {
Scanner in = new Scanner(System.in);
String input = "";
Float x;
Integer y;
System.out.println("Введите координаты: ");
do {
System.out.print("x: ");
if (in.hasNextLine())
input = in.nextLine();
else {
System.out.println("Плохой символ");
System.exit(0);
}
} while(!Menu.isFloat(input));
x = Float.parseFloat(input);
do {
System.out.print("y: ");
if (in.hasNextLine())
input = in.nextLine();
else {
System.out.println("Плохой символ");
System.exit(0);
}
} while(!Menu.isInteger(input));
y = Integer.parseInt(input);
return new Coordinates(x, y);
}
public String parse(char del) {
return Float.toString(x) + del + y;
}
@Override
public String toString() {
return "Coordinates{" +
"x=" + x +
", y=" + y +
'}';
}
}