Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
76 lines (72 loc) · 2.92 KB
/
Copy pathMain.java
File metadata and controls
76 lines (72 loc) · 2.92 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Здравствуйте! На сколько гостей разделить счёт?");
int guest;
while (true) {
Scanner scanner = new Scanner(System.in);
if (scanner.hasNextInt()) {
guest = scanner.nextInt();
if (guest > 1) {
System.out.println("Количество гостей " + guest);
break;
} else if (guest == 1) {
System.out.println("Счёт выставлен на 1 гостя");
}
} else {
System.out.println("Произошла ошибка");
scanner.reset();
}
}
String product;
float price;
float totalPrice = 0;
String goods = "";
while (true) {
Scanner scanner = new Scanner(System.in);
System.out.println("Выберите блюдо");
product = scanner.nextLine();
scanner.reset();
System.out.println("Укажите цену");
if (scanner.hasNextFloat()) {
price = scanner.nextFloat();
if (price <= 0) {
System.out.println("Произошла ошибка");
} else {
Scanner scanner1 = new Scanner(System.in);
totalPrice = totalPrice + price;
goods = goods + product;
System.out.println("Блюдо в корзине");
System.out.println("Добавить ещё или \"Завершить\"?");
String check = scanner1.nextLine();
scanner1.reset();
String complete = "Завершить";
if (check.equalsIgnoreCase (complete)) {
System.out.println("Блюда в корзине:" + "\n"+ goods);
String payment = "Итого каждому к оплате: %.2f %s";
Rouble ending = new Rouble();
System.out.println(String.format(payment, totalPrice / guest, ending.ending(totalPrice/guest)));
break;
}
}
}
}
}
}
class Rouble {
public String ending(double rubles) {
int ending = (int) (Math.floor(rubles) % 10);
if (((int) (Math.floor(rubles) % 100)) <= 19 && ((int) (Math.floor(rubles) % 100)) >= 11)
return "рублей";
switch (ending) {
case 1:
return "рубль";
case 2:
case 3:
case 4:
return "рубля";
default:
return "рублей";
}
}
}