forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
65 lines (53 loc) · 2.13 KB
/
Calculator.java
File metadata and controls
65 lines (53 loc) · 2.13 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
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Calculator {
public static int calculator(){
int totalPersons = 0;
Scanner scanner = new Scanner(System.in);
System.out.println("На сколько человек необходимо разделить счет?");
while (!scanner.hasNextInt()){
System.out.println("Допустимы только цифры, попробуйте еще раз");
scanner.next();
}
while (scanner.hasNextInt()) {
int persons = scanner.nextInt();
if (persons == 1) {
System.out.println("Ничего считать не буду");
} else if (persons < 1) {
System.out.println("Некорректное значение, пробуй еще");
}
else {
totalPersons += persons;
break;
}
}
return totalPersons;
}
public static double stuffCost(){
double totalCOst = 0.0;
String keyWord = "завершить";
ArrayList<String> allNames = new ArrayList<>();
double price;
while (true) {
System.out.println("Введите название товара");
String name = Stuff.name();
allNames.add(name);
System.out.println("Введите стоимость товара");
price = Stuff.priceStuf(name);
if (name.equalsIgnoreCase(keyWord)) {
System.out.println("Ну ладно");
System.out.println("Добавленные товары: ");
for (int i = 0; i < allNames.size() - 1; i++) {
System.out.println(allNames.get(i));
}
break;
} else if (name.matches("[-+]?\\d+")) {
System.out.println("Попробуй еще раз");
break;
}
totalCOst += price;
}
return totalCOst;
}
}