Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
58 lines (51 loc) · 2.27 KB
/
Copy pathMain.java
File metadata and controls
58 lines (51 loc) · 2.27 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
byte friends;
String order;
String table = "";
float price;
float total = 0.0f;
String exit;
while (true) {
System.out.println("Введите число участников:");
Scanner who = new Scanner(System.in);
if (who.hasNextByte()) {
friends = who.nextByte();
if (friends <= 1) {
System.out.println("Нет смысла делить счёт. Попробуйте ещё раз.");
} else {
break;
}
} else {
System.out.println("Требуется указать числовое значение!");
}
}
while (true) {
System.out.println("Введите название блюда:");
Scanner input = new Scanner(System.in);
order = input.nextLine();
table += order + "\n";
System.out.println("Стоимость в формате 'руб,коп':");
if (input.hasNextFloat()) {
price = input.nextFloat();
if (price > 0) {
total += price;
System.out.println("Товар успешно добавлен!\nПродолжить? Да/Завершить");
exit = input.next();
if (exit.equalsIgnoreCase("Завершить")) {
break;
}
} else {
System.out.println("Отрицательное значение.");
}
} else {
System.out.println("Неверно указана сумма, попробуйте снова.");
}
}
Ending name = new Ending();
System.out.println("Добавленные товары:\n" + table);
System.out.println("Общая стоимость блюд: " + String.format("%.2f", total) + " " + name.end(total));
System.out.println("Сумма к оплате каждым участником: " + String.format("%.2f", total/friends) + " " + name.end(total/friends));
}
}