forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnterData.java
More file actions
79 lines (73 loc) · 3.01 KB
/
EnterData.java
File metadata and controls
79 lines (73 loc) · 3.01 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
68
69
70
71
72
73
74
75
76
77
78
79
import java.math.BigDecimal;
import java.util.Scanner;
public class EnterData {
public static int enterGuest(Integer countInCheck){
int person;
while (true) {
System.out.println("Введите гостя: ");
try {
Scanner scanner = new Scanner(System.in);
person = scanner.nextInt();
if ((person > 0)&&(person<=countInCheck)) {
break;
}
} catch (Exception ex) {
}
System.out.println("Введите число от 1 до "+countInCheck);
}
return person;
}
public static BigDecimal enterPrice(){
BigDecimal price;
String readLine;
while (true) {
System.out.println("Введите цену блюда: ");
try {
Scanner scanner = new Scanner(System.in);
readLine = scanner.nextLine();
if(readLine.trim().length()-readLine.trim().indexOf(".")<=3||readLine.trim().indexOf(".")==-1) {
price = new BigDecimal(readLine);
//Предыдущее условие >= соответствовало критериям задачи, стоимость не могла быть отрицательной, в данном случае она не может быть и нулевой,
//хотя вполне могут быть подарки от заведения, акции или просто замена блюда.
if(price.compareTo(BigDecimal.ZERO)>0){
break;
}
}
} catch (Exception ex) {
}
System.out.println("Введена некорректная цена");
}
return price;
}
public static String enterDish(){
String nameDish;
//Ввод наименования блюда
while(true) {
System.out.println("Введите наименование блюда: ");
Scanner scanner = new Scanner(System.in);
nameDish = scanner.nextLine();
if(nameDish.length()>0){
break;
}
}
return nameDish;
}
public static Integer enterCountOfGuests(){
Integer countPerson;
while (true) {
System.out.println("Введите количество гостей (> 1): ");
try {
Scanner scanner = new Scanner(System.in);
countPerson = scanner.nextInt();
if (countPerson > 1) {
break;
}else {
System.out.println("Ошибка: Введено число не удовлетворяющее требованиям!");
}
} catch (Exception ex) {
System.out.println("Ошибка: Введено некорректное значение!");
}
}
return countPerson;
}
}