Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
68 lines (51 loc) · 2.86 KB
/
Copy pathMain.java
File metadata and controls
68 lines (51 loc) · 2.86 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
import java.util.Scanner;
// dev branch for Y.Practicum
public class Main {
public static void main(String[] args) {
int members = 0;
Scanner scanner= new Scanner(System.in);
System.out.println("Пожалуйства введите количество человек");
while (members <= 1) {
if (scanner.hasNextInt()) {
members = scanner.nextInt();
if (members <= 1) {
System.out.println("Количетсво введенных пользователей меньше или равно 1, пожалуйства попробуйте снова");
}
} else {
System.out.println("Нужно ввести число!");
scanner.next();
}
} //конец цикла подсчета участников
Product product = new Product(); //объект продукт
Calculator calculator = new Calculator();
while (true) { //начало подсчета товара
System.out.println("Введите название товара");
product.name = scanner.next();
if (product.name.equalsIgnoreCase("Завершить")) {
break;
}
System.out.println("Введите цену товара");
while (!scanner.hasNextDouble()) {
System.out.println("Неккоректный ввод, попробуйте снова");
scanner.next();
}
product.price = scanner.nextDouble();
while (product.price <= 0) {
System.out.println("Пожалуйства введите цену больше 0");
while (!scanner.hasNextDouble()) {
System.out.println("Неккоректный ввод, попробуйте снова");
scanner.next();
}
product.price = scanner.nextDouble();
}
product.priceList = calculator.calculate(members, product.price);
product.nameList = product.productList(product.name);
System.out.println("Вы хотите добавить новый товар?, либо введите Завершить");
} //конец подсчета
Formatter formatter = new Formatter();
//объект формата строки
System.out.println("Ваш товар: " + " \n" + product.nameList);
System.out.println("На сумму: " + String.format("%.2f", product.priceList) + " " + formatter.numFormat(product.priceList));
System.out.println("Каждый должен заплатить: " + String.format("%.2f", (product.priceList/members)) + " " + formatter.numFormat(product.priceList/members));
}
}