Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
105 lines (92 loc) · 3.87 KB
/
Copy pathMain.java
File metadata and controls
105 lines (92 loc) · 3.87 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.Random;
import java.util.Scanner;
// dev branch for Y.Practicum
public class Main {
static CountPersons countPersons = new CountPersons();
static int persons = 0;
static double sum = 0;
public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
countPersons.quantityOfPersons();
addProduct();
finish();
}
public static class CountPersons {
void quantityOfPersons() {
Scanner scanner = new Scanner(System.in);
System.out.println("Сколько вас человек?");
while (true) {
if (scanner.hasNextInt()) {
persons = scanner.nextInt();
if (persons == 1) {
System.out.println("Вы один, нет смысла делить.");
} else if (persons < 1) {
System.out.println("Неверное значение меньше 1");
} else if (persons > 1) {
break;
} else {
System.out.println("Вы ввели не число");
scanner.nextLine();
}
}
}
}
}
public static void addProduct() {
Scanner scanner = new Scanner(System.in);
double price = 0;
String productList = "Добавленные товары: \n";
String product = null;
System.out.println("напишите блюдо");
while ((product = scanner.nextLine()) != null) {
if (product.equalsIgnoreCase("Завершить")) {
System.out.println(productList);
String str2 = String.format("Общая сумма товаров составила: %.2f", sum);
System.out.println(str2);
break;
}
System.out.println("сколько стоит блюдо?");
while (true) {
if (scanner.hasNextDouble()) {
price = scanner.nextDouble();
if (price < 0) {
System.out.println("Введённая сумма меньше 0");
} else if (price >= 0) {
sum += price;
productList += product + "\n";
String str = String.format("%s стоимостью %.2f добавлено. Сумма: %.2f", product, price, sum);
System.out.println(str);
System.out.println("напишите блюдо");
break;
} else {
System.out.println("Введено не число");
scanner.nextLine();
}
}
}
scanner.nextLine();
}
}
public static void finish() {
double total = sum/persons;
int num1 = (int) (total);
String result = null;
if (total % 100 > 4 && total % 100 < 21) {
result = "рублей";
} else if (total % 10 == 1) {
result = "рубль";
} else if (total % 10 > 1 && total % 10 < 5) {
result = "рубля";
}
int num2 = persons;
String result2 = null;
if (num2 % 100 > 4 && num2 % 100 < 21) {
result2 = "человека";
} else if (num2 % 10 > 1 && num2 % 10 < 5) {
result2 = "человек";
String str = String.format("Вас %d %s, С каждого по %.2f %s", persons, result2, total, result);
System.out.println(str);
}
}
}