-
Notifications
You must be signed in to change notification settings - Fork 218
Expand file tree
/
Copy pathMain.java
More file actions
54 lines (46 loc) · 2 KB
/
Main.java
File metadata and controls
54 lines (46 loc) · 2 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
import java.util.InputMismatchException;
import java.util.Scanner;
public class Main {
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
Calculator calculator = new Calculator();
System.out.println("На скольких человек разделить счет?");
int scanPerson;
while (true) {
if (scanner.hasNextInt()) {
scanPerson = scanner.nextInt();
if (scanPerson == 1) {
System.out.println("Подсчет не нужен");
System.exit(0);
} else if (scanPerson < 1) {
System.out.println("Ошибка. Введите корректное значение.");
} else break;
} else {
System.out.println("Введите корректное значение");
scanner.nextLine();
}
}
calculator.setCountPerson(scanPerson);
do {
Product product = new Product();
System.out.println("Введите название товара");
scanner.nextLine();
product.setNameOfProduct(scanner.nextLine());
System.out.println("Введите стоимость товара в формате 00,00");
product.setCost(inputPrice());
calculator.setBill(product);
System.out.println("Завершить? Нажмите любой символ, чтобы продолжить");
} while (!scanner.next().equalsIgnoreCase("Завершить"));
calculator.calculate();
}
static double price = 0.0;
public static double inputPrice() {
try {
price = scanner.nextDouble();
} catch (InputMismatchException exception) {
System.out.println("Введите корректное значение");
scanner.nextLine();
inputPrice();
} return price;
}
}