Repository navigation
Expand file tree
/
Copy pathCalculate.java
More file actions
67 lines (60 loc) · 3.12 KB
/
Copy pathCalculate.java
File metadata and controls
67 lines (60 loc) · 3.12 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
import java.util.Scanner;
public class Calculate {
class Product {
String name;
double price;
void input() {
Scanner scanner = new Scanner(System.in);
System.out.println("Введите наименование товара");
name = scanner.next();
System.out.println("Введите стоимость товара в формате [руб,коп]");
while (true) {
if (scanner.hasNextDouble()) {
price = scanner.nextDouble();
if (price < 0) {
System.out.println("Введено недопустимое значение.Введите число больше 0 ");
scanner.nextLine();
} else {
break;
}
} else {
System.out.println("Введено недопустимое значение. Введите число больше 0");
scanner.nextLine();
}
}
}
}
Product product = new Product();
double sum = 0.00f;
String menu = "";
Scanner scannerAdd = new Scanner(System.in);
int persons = Main.countOfGuests();// ссылка на число гостей из класса майн
public void receipt() {
while (true) {
product.input();
menu = menu.concat(product.name).concat("\n");
sum = sum + product.price;
System.out.println("Товар успешно добавлен");
System.out.println("Чтобы завершить добавление товаров введите [Завершить].\n\nДля продолжения внесения товаров введите любое другое значение.");
String add = scannerAdd.next();
if (add.equalsIgnoreCase("Завершить")) {
System.out.println("Список товаров:\n" + menu);
double personPay = sum / persons; // сумма на каждого человека
if ((Math.floor(personPay) % 100 >= 11) && (Math.floor(personPay) % 100 <= 19)) {
String format = "Каждый гость должен: %.2f рублей";
System.out.println(String.format(format, personPay));
} else if (Math.floor(personPay) % 10 > 5) {
String format = "Каждый гость должен: %.2f рублей";
System.out.println(String.format(format, personPay));
} else if ((2 <= Math.floor(personPay) % 10) && (Math.floor(personPay) % 10 <= 4)) {
String format = "Каждый гость должен: %.2f рубля";
System.out.println(String.format(format, personPay));
} else {
String format = "Каждый гость должен: %.2f рубль";
System.out.println(String.format(format, personPay));
}
break;
}
}
}
}