-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathMain.java
More file actions
47 lines (37 loc) · 2.01 KB
/
Main.java
File metadata and controls
47 lines (37 loc) · 2.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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
printMenu();
String quantityOfPersons = scanner.nextLine();
int number = -1;
try {
number = Integer.parseInt(quantityOfPersons);
} catch (NumberFormatException e) {
System.out.println("Вы ввели что-то не то... Давайте ещё раз.");
}
if (number == 1) {
System.out.println("Тебе грустно и одиноко, нечем заняться? Занимайся Джаббой!");
} else if (number > 1) {
System.out.println("Итак, вас " + quantityOfPersons + ". И вы харчевали...");
Item.calculate();
double pricePerPerson = Item.sum / number;
System.out.println("\nКаждый из посетителей должен заплатить " + String.format("%.2f", pricePerPerson) + CaseEnding.setEnding(pricePerPerson) + ".");
System.out.println("Вычисления завершены. Выход.");
break;
} else if (number == 0) {
System.out.println("Выход, потому что кое-кто нажал ноль.");
break;
} else {
System.out.println("Введите положительное число гостей.");
}
}
}
public static void printMenu() {
System.out.println("\nДобрый день!");
System.out.println("На скольких человек вы хотите разделить счёт?");
System.out.println("Пожалуйста, введите количество гостей - от 1 и выше.");
System.out.println("Или введите 0 для того, чтобы выйти из программы.");
}
}