Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
56 lines (43 loc) · 1.67 KB
/
Copy pathMain.java
File metadata and controls
56 lines (43 loc) · 1.67 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
// dev branch for Y.Practicum
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
firstStep();
int persons = checkInput();
Calculator calculator = new Calculator();
List<Product> products = calculator.calculateBill();
System.out.println("------------------------");
Product.calculation(persons, sumTotal(products));
}
public static void firstStep() {
System.out.println("Добрый день! Это консольное приложение пожет вам разделить счет");
System.out.println("Введите количество персон");
}
public static int checkInput() {
Scanner scanner = new Scanner(System.in);
int input;
while (true) {
if (!scanner.hasNextInt()) {
System.out.println("Введите число виде числа персон!");
scanner.next();
continue;
} else input = scanner.nextInt();
if (input <= 1) {
System.out.println("Ошибка! Введите количество персон больше 1 человека");
continue;
}
break;
}
return input;
}
public static double sumTotal(List<Product> productList) {
double total = 0;
for (Product product : productList) {
total = total + product.price;
String text = "Позиция - " + product.name + " по цене " + product.price;
System.out.println(text);
}
return total;
}
}