Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
94 lines (71 loc) · 3.89 KB
/
Copy pathMain.java
File metadata and controls
94 lines (71 loc) · 3.89 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
final String STOP_VALUE = "завершить";
Calculator.setNumberOfPeoples(inputPeopels());
Product product = new Product();
System.out.println("Отлично, вы не один! Вам нужно ввести наименование товаров и их цену.");
while(true){
product.setNameProduct(inputNameProduct());
Calculator.makeListOfProducts(product);
product.setPriceProduct(inputPriceProduct());
Calculator.countSumOnBill(product);
System.out.println("\n"+"******Ваш товар добавлен успешно!******"+"\n");
System.out.print ("Если хотите завершить добавление товаров, наберите \"завершить\", если нет - введите любой символ: ");
Scanner scanner = new Scanner(System.in);
if(scanner.next().equalsIgnoreCase(STOP_VALUE))
break;
}
System.out.println(Calculator.getListProducts());
System.out.print("Общая сумма для оплаты: " + Formatting.getFormattingDouble(Calculator.getSumOfProducts()));
System.out.println(" " + Formatting.getFormattingEnding(Calculator.getSumOfProducts()));
System.out.print("Сумма оплаты для одного человека: " + Formatting.getFormattingDouble(Calculator.getSumForOnePeople()));
System.out.println(" " + Formatting.getFormattingEnding(Calculator.getSumForOnePeople()) + ". Вместе дешевле и веселее!");
}
private static int inputPeopels () {
Scanner scanner = new Scanner(System.in);
int numberOfPeoples;
while (true) {
System.out.print("Ввидите число людей, на которых нужно разделить счет: ");
try {
numberOfPeoples = Integer.parseInt(scanner.next());
if (numberOfPeoples == 1)
{
System.out.println("Похоже вы один... Вам счет делить не с кем =(. Введите другое число.");
continue;
}
else if (numberOfPeoples <= 0){
System.out.println("Ввидите значение больше нуля. Попробуйте еще раз.");
continue;
}
break;
} catch (NumberFormatException exp) {
System.out.println("Не корректный ввод! Ввидите число.");
}
}
return numberOfPeoples;
}
private static String inputNameProduct (){
Scanner scanner = new Scanner(System.in);
System.out.print("Введите название товара:");
return scanner.nextLine();
}
private static double inputPriceProduct () {
Scanner scanner = new Scanner(System.in);
double priceProduct;
while (true) {
System.out.print("Введите стоимость товара в следующем формате: \"'рубли.копейки' [10.45, 11.40]\": ");
try {
priceProduct = Double.parseDouble(scanner.next());
if (priceProduct <= 0){
System.out.println("Вы ввели отрицательную стоимость. Такое может быть, но не в этой жизни =(.");
continue;
}
break;
} catch (NumberFormatException exp) {
System.out.println("Не корректный ввод! Ввидите число в указанном формате.");
}
}
return priceProduct;
}
}