Repository navigation
Expand file tree
/
Copy pathProducts.java
More file actions
50 lines (43 loc) · 2.43 KB
/
Copy pathProducts.java
File metadata and controls
50 lines (43 loc) · 2.43 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
import java.util.Scanner;
public class Products {
static String exit = "ЗАВЕРШИТЬ";
public static void calc(int people) {
String product;
String allProducts = "";
float costPrice;
float sumForall = 0.00f;
String close;
while (true) {
Scanner scanner2 = new Scanner(System.in);
System.out.println("Введите название товара");
product = scanner2.nextLine();
System.out.println("Товар " + product + " добавлен в счёт");
System.out.println("Введите стоимость товара в формате: 'рубли.копейки' [пример - 10.45, 11.40]");
if (scanner2.hasNextFloat()) {
costPrice = scanner2.nextFloat();
if (costPrice > 0) {
sumForall = sumForall + costPrice;
allProducts = allProducts + product + "\n";
String sufForOne = Calculator.complete(costPrice);
String anotherOne = "Вы добавили: %s за %.2f%s\n";
System.out.printf(anotherOne, product, costPrice, sufForOne);
System.out.println("Введите любой символ, если хотите добавить товар. В противном случае введите:'ЗАВЕРШИТЬ'");
close = scanner2.next();
if (close.equalsIgnoreCase(exit)) {
break;
}
} else {
System.out.println("Сумма указана неверно");
}
} else {
System.out.println("Некорректный формат стоимости товара. Побробуйте ввести сумму ещё раз!");
}
}
String suf = Calculator.complete(sumForall);
float forOneguest = sumForall/ people;
String lastSuf = Calculator.complete(forOneguest);
System.out.println("Вы купили:\n" + allProducts + "За " + String.format("%.2f", sumForall) + suf);
System.out.println("Каждый из гостей должен заплатить: " + String.format("%.2f", forOneguest) + lastSuf);
System.out.println("Спасибо,что воспользовались нашим Калькулятором - счётчиком!");
}
}