forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.java
More file actions
65 lines (39 loc) · 1.4 KB
/
Input.java
File metadata and controls
65 lines (39 loc) · 1.4 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
import java.util.Scanner;
public class Input {
Scanner scanner = new Scanner(System.in);
public int getInteger(String message ) {
System.out.println( message);
while (true) {
if( !scanner.hasNextInt() ) {
System.out.println( message);
scanner.nextLine(); }
else {
int kolichestvo = scanner.nextInt();
scanner.nextLine();
if (kolichestvo>1) return kolichestvo;
System.out.println("Вы указали неверное значение, укажите значение больше 1.");
}
}
}
public String getString (String message) {
System.out.println( message);
String nameProduct = scanner.nextLine();
return nameProduct;
}
public double getDouble(String message ) {
System.out.println( message);
while (true) {
if( !scanner.hasNextDouble() ) {
System.out.println( message);
scanner.nextLine(); }
else {
double cena = scanner.nextDouble();
scanner.nextLine();
if (cena>0) return cena;
else {
System.out.println( "Неверно указана цена. Укажите верную цену");
}
}
}
}
}