forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasket.java
More file actions
83 lines (63 loc) · 2.68 KB
/
Basket.java
File metadata and controls
83 lines (63 loc) · 2.68 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
import static com.sun.tools.doclint.Entity.sum;
import com.sun.tools.doclint.Entity;
import java.util.Scanner;
public class Basket {
public static void fillProductInfo() {
Scanner productScanner = new Scanner(System.in);
int friends = Friends.comeFriends();
String rouble = Rubles.writeRouble();
String name = null;
double price = 0;
String nameList = " набрали: ";
double sum = 0;
double payPerFriend = 0;
System.out.println("Что взяли? ");
while ((name = productScanner.next()) != null) {
nameList += " " + name + "\n";
System.out.println("И почём сие добро?");
if (productScanner.hasNextDouble()) {
price = productScanner.nextDouble();
productScanner.nextLine();
if (price <= 0) {
System.out.println("Таких цен не бывает");
} else if (price > 0) {
sum += price;
payPerFriend = sum / friends;
double result = Double.parseDouble(String.format("%.2f", payPerFriend));
}
System.out.println("Добавили " + name + " по цене " + price + ", товаров на общую сумму " + sum);
} else {
System.out.println("Что-то не то. Давайте всё по-новой");
productScanner.nextLine();
}
if (name.equalsIgnoreCase("завершить")) {
String text = "Вы" + nameList + "С каждого человека %.2f";
System.out.println(String.format(text, payPerFriend) + rouble);
break;
}
System.out.println("Если вы сегодня на легке, или в вас больше ничего не лезет, напишите \"Завершить\", \nили напишите следующий продукт");
}
}
public String writeRouble() {
String rouble;
double payPerFriend = 0;
int intPayPerFriend = (int) payPerFriend;
if (intPayPerFriend % 100 >= 10 && intPayPerFriend % 100 <= 20) {
rouble = " рублей";
} else {
switch (intPayPerFriend % 10) {
case 1:
rouble = " рубль";
break;
case 2:
case 3:
case 4:
rouble = " рубля";
break;
default:
rouble = " рублей";
}
}
return rouble;
}
}