-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.java
40 lines (34 loc) · 1 KB
/
Input.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
import java.util.Scanner;
import java.util.InputMismatchException;
public class Input {
private Scanner scanner;
public Input() {
scanner = new Scanner(System.in);
}
public int getPositionInput() {
int position = 0;
try {
position = scanner.nextInt();
} catch (InputMismatchException exception) {
PrintHelper.integerOnlyMsg();
scanner.nextLine();
}
return position;
}
public int getConnectNInput() {
int connectN = 0;
PrintHelper.showConnectNumMsg();
do {
try {
connectN = scanner.nextInt();
if (connectN <= 2 || connectN >= 7) {
PrintHelper.showConnectNErrorMsg();
}
} catch (InputMismatchException exception) {
PrintHelper.showConnectNErrorMsg();
scanner.nextLine();
}
} while (connectN <= 2 || connectN >= 7);
return connectN;
}
}