Repository navigation
Expand file tree
/
Copy pathRock.java
More file actions
73 lines (69 loc) · 2.7 KB
/
Copy pathRock.java
File metadata and controls
73 lines (69 loc) · 2.7 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
import java.util.Scanner;
public class Rock {
Scanner scanner = new Scanner(System.in);
int personCheck;
float fullPrice;
float priceForOne;
float price;
String product;
String fullProduct = "Добавленные товары: ";
String rub = " Рублей";
public void person() {
System.out.println("Введите количество на сколько человек необходимо разделить счёт");
while (true) {
if (!scanner.hasNextInt()) {
System.out.println("Введите целое число, а не " + scanner.nextLine());
continue;
} else {
personCheck = scanner.nextInt();
break;
}
}
}
public void morePerson() {
while (personCheck <= 1) {
System.out.println("Некорректное значение, введите число больше 1");
person();
if (personCheck > 1) {
break;
}
}
}
void addProduct() {
System.out.print("Введите название товара: ");
product = scanner.nextLine();
product = scanner.nextLine();
System.out.print("Введите стоимость товара в формате \"рубли.копейки\": ");
price = scanner.nextFloat();
System.out.println("Товар успешно добавлен!\n");
fullProduct = fullProduct + "\n" + product ;
fullPrice += price;
}
void addMoreProduct(){
String end = "Завершить";
String yes = "Да";
while (true) {
System.out.println("Хотите добавить ещё товар?\nДля продолжения введите: " + yes + "\nДля завершения введите: " + end);
product = scanner.nextLine();
product = scanner.nextLine(); // что бы не печатало то что выше 2 раза
if (yes.equalsIgnoreCase(product)){
addProduct();
continue;
}
if (end.equalsIgnoreCase(product)){
System.out.println(fullProduct);
String.format("%.2f",fullPrice);
System.out.println("Сумма товаров: " + fullPrice);
break;
}
}
}
public void endCalculator(){
priceForOne = fullPrice / personCheck;
if (Math.floor(priceForOne) < 5) {
rub = " Рубль";
}
String.format("%.2f", priceForOne);
System.out.println("Сумма на человека: " + priceForOne + rub);
}
}