Repository navigation
Expand file tree
/
Copy pathCalculator.java
More file actions
62 lines (52 loc) · 2.26 KB
/
Copy pathCalculator.java
File metadata and controls
62 lines (52 loc) · 2.26 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
import java.util.Scanner;
public class Calculator {
double totalPrice;
double priceForPerson;
double price;
int numberOfPeople = 1;
String productList = "Добавленные товары:";
void priceForPerson() {
priceForPerson = totalPrice / numberOfPeople;
Formatter formatter = new Formatter();
formatter.formatRub(priceForPerson);
System.out.println(String.format("Каждый человек должен заплатить %.2f %s", priceForPerson, formatter.rub));
}
void addProduct() {
System.out.println("Введите наименование товара");
Scanner scanner = new Scanner(System.in);
String input="";
while (true) {
if(input.isEmpty()) {
input = scanner.next();
}
productList = productList + "\n" + input;
System.out.println("Введите цену товара в формате рубли,копейки");
price = scanner.nextFloat();
totalPrice = totalPrice + price;
System.out.println("Товар добавлен");
System.out.println("Для продолжения введите наименование следующего товара. Для окончания подсчёта введите \"Завершить\"");
input = scanner.next();
if (input.equalsIgnoreCase("Завершить")) {
System.out.println(productList);
break;
}
}
}
void getNumberOfPeople () {
System.out.println("Введите число человек, на которых необходимо разделить счёт");
Scanner scanner = new Scanner(System.in);
while (true) {
if (scanner.hasNextInt()) {
numberOfPeople = scanner.nextInt();
if (numberOfPeople > 1) {
break;
} else {
System.out.println("Некорректное число. Порпробуйте снова");
}
} else {
System.out.println("Неоходимо ввести число");
scanner.next();
}
}
}
}