forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyScanner.java
More file actions
40 lines (26 loc) · 853 Bytes
/
MyScanner.java
File metadata and controls
40 lines (26 loc) · 853 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
38
39
40
import java.io.InputStream;
import java.util.Scanner;
public final class MyScanner {
private final Scanner scanner;
public String next() { return scanner.next(); }
public int nextInt() { return (int) nextDouble(); }
public double nextDouble() {
return readValue(scanner.next());
}
private double readValue(final String value) {
double newValue;
try {
newValue = Double.parseDouble(value);
} catch(NumberFormatException e) {
newValue = -1;
}
return newValue;
}
public void close() {
scanner.close();
}
public static void errorMessage() { System.out.println("Недопустимый ввод, попробуйте ещё раз"); }
public MyScanner(InputStream in) {
this.scanner = new Scanner(in);
}
}