forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
47 lines (39 loc) · 2.04 KB
/
Calculator.java
File metadata and controls
47 lines (39 loc) · 2.04 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
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Calculator {
public static void GoodsPrice() {
int kol = Main.getPeopleCount();
ArrayList<Product> products = new ArrayList<>();
double allPrices = 0;
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Введите название товара");
String nameGoods = scanner.nextLine();
if (nameGoods.equalsIgnoreCase("Завершить")) {
break;
} else {
System.out.println("Введите цену товара");
if (scanner.hasNextDouble()) {
double priceGoods = scanner.nextDouble();
products.add(new Product(nameGoods, priceGoods));
allPrices = allPrices + priceGoods;
System.out.println("Товар добавлен");
}
else {
System.out.println("Цена введена неправильно.Попробуйте еще раз");
}
scanner.nextLine();
}
}
System.out.println("Добавленные товары:");
for (int i=0; i<products.size();i++){
System.out.println(products.get(i).name+" за "+products.get(i).price);
}
System.out.println("Общая сумма: "+ String.format("%.2f", allPrices));
int price= (int) (allPrices/kol);
if(price % 100 > 10 && price % 100 < 20 || price % 10 == 0 || price % 10 > 4) System.out.println("Каждый должен заплатить "+ String.format("%.2f", allPrices/kol)+ " рублей");
else if(price % 10 > 1 && price % 10 < 5) System.out.println("Каждый должен заплатить "+ String.format("%.2f", allPrices/kol)+ " рубля");
else System.out.println("Каждый должен заплатить "+ String.format("%.2f", allPrices/kol)+ " рубль");
}
}