Repository navigation
Expand file tree
/
Copy pathCalculate.java
More file actions
103 lines (94 loc) · 4.17 KB
/
Copy pathCalculate.java
File metadata and controls
103 lines (94 loc) · 4.17 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
import java.util.ArrayList;
import java.util.Scanner;
public class Calculate {
static Const aConst=new Const();
static Scanner scanner = new Scanner(System.in);
static ArrayList<String> product = new ArrayList<>();
static ArrayList<Double> price = new ArrayList<>();
static double score = 0;
public static void calculate() {
int count;
while (true){
while (true)//проверка ввода целого числа
{
System.out.println("На сколько человек разделить заказ?");
System.out.println("Введите целое больше 1");
if (scanner.hasNextInt())
{
count = Integer.parseInt(scanner.nextLine());
System.out.println("Вы ввели: " + count);
break;
}
else
{
System.out.println("Вы ввели не целое число");
scanner.nextLine();
}}
if (count<=1) {
System.out.println("Оглянись! Ты тут один наел на 15 тысяч");
} else {
//блок заполнения листа и подсчета счета
System.out.println(aConst.ADD_PRODUCT_AND_PRICE);
String nameProduct = scanner.next();//название продукта
Double priceProduct = scanner.nextDouble();//цена
addProduct(nameProduct);
addPrice(priceProduct);
System.out.println(aConst.ADD_MESSAGE_PRODUCT);
while (true) {
System.out.println(aConst.QUESTION_MESSAGE);
String question = scanner.next();
if (question.equalsIgnoreCase("Да")) {
System.out.println(aConst.ADD_PRODUCT_AND_PRICE);
String addNameProduct = scanner.next();
double addPriceProduct = scanner.nextDouble();
addProduct(addNameProduct);
addPrice(addPriceProduct);
System.out.println(aConst.ADD_MESSAGE_PRODUCT);
} else if (question.equalsIgnoreCase("Завершить")) {
printProductAndPrice();
score = score / count;
printResult(score);
break;
}
}
break;
}
}
}
private static void addProduct(String addProduct) {
product.add(addProduct);
}
private static void addPrice(Double addPrice) {
price.add(addPrice);
}
//ввывод товаров и стоимость каждого продукта
private static void printProductAndPrice() {
System.out.println("Добавленные товары:");
for (double price : price) {
score = score + Math.abs(price);
}
for (int i=0;i<product.size();i++){
System.out.println("Продукт: "+ product.get(i)+ " стоимость: "+ Math.abs(price.get(i)));
}
}
//метод для вывода окончания рубля
private static void printResult(double score1) {
if ( Math.floor(score1) % 100 >= 11 && Math.floor(score1) % 100 <= 19) {
System.out.printf("Каждый должен заплатить: %.2f Рублей%n",score1);
} else {
switch ((int) (Math.floor(score1) % 10)) {
case 1:
System.out.printf("Каждый должен заплатить: %.2f Рубль%n",score1);
break;
case 2:
case 3:
case 4:
System.out.printf("Каждый должен заплатить: %.2f Рубля%n",score1);
break;
default:
System.out.printf("Каждый должен заплатить: %.2f Рублей%n",score1);
break;
}
}
}
}