forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
90 lines (74 loc) · 2.75 KB
/
Main.java
File metadata and controls
90 lines (74 loc) · 2.75 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
import java.util.Scanner;
// dev branch for Y.Practicum
public class Main {
static Scanner scanner = new Scanner(System.in);
static int numberOfPayer;
static Basket basket = new Basket();
public static void main(String[] args) {
System.out.println("на скольких делить?");
numberOfPayer = calcPayer();
System.out.println(numberOfPayer);
requestItem();
basket.printBasket();
System.out.println("каждый заплатит " + check() + " " + padej());
}
public static int calcPayer() {
int num;
while (true) {
if (!scanner.hasNextInt()) {
System.out.println("введи число");
scanner.next();
} else {
num = scanner.nextInt();
if (num < 1) {
System.out.println("не на кого делить");
} else if (num == 1) {
System.out.println("сам плати");
} else
break;
}
}
return num;
}
public static void requestItem() {
String key;
float value;
while (true) {
System.out.println("если закончил с покупками то набери 'Завершить' иначе введи наименование товара и цену");
key = scanner.next();
if (key.equalsIgnoreCase("Завершить")) {
break;
}
basket.addKey(key);
while (true) {
scanner.nextLine();
if (!scanner.hasNextFloat()) {
System.out.println("введи значение в формате ХХ,ХХ");
} else {
value = scanner.nextFloat();
if (value < 0) {
System.out.println("цена не может быть отрицательной");
} else break;
}
}
basket.addValue(value);
System.out.println("успешно добавленно в корзину");
System.out.println("=============");
}
}
public static float check() {
return (float) Math.round((basket.sumBuy() / numberOfPayer) * 100) / 100;
}
public static String padej() {
int floor = (int) check();
if ((floor % 10) ==0 || (floor % 100) >= 10 && (floor % 100) <= 20) {
return "рублей";
} else if (floor % 10 > 1 && (floor % 10) < 5) {
return "рубля";
} else if (floor % 10 >= 5) {
return "рублей";
} else {
return "рубль";
}
}
}