Repository navigation
Expand file tree
/
Copy pathCalculator.java
More file actions
61 lines (54 loc) · 2.12 KB
/
Copy pathCalculator.java
File metadata and controls
61 lines (54 loc) · 2.12 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
import java.util.Scanner;
public class Calculator {
double total;
String products = "Добавленные продукты:\n";
Scanner scanner = new Scanner(System.in);
void addProducts() {
while (true) {
Product product = new Product();
System.out.println("Введите наазвание товара:");
product.name = scanner.next();
while (true) {
System.out.println("Введите стоимость товара в формате ('рубли.копейки' [10.45, 11.40]):");
String strPriceProduct = scanner.next();
try {
product.price = Double.parseDouble(strPriceProduct);
} catch (NumberFormatException error) {
System.out.println("Стоимость указана в некорректном формате.");
continue;
}
if (product.price > 0) {
break;
}
System.out.println("Ошибка. Значение стоимости введено некорректно.");
}
System.out.println("Товар уcпешно добавлен. Хотите добавить еще товар?");
total = total + product.price;
products = products + product.name + "\n";
String NoOrYes = scanner.next();
if (NoOrYes.equalsIgnoreCase("Завершить")) {
break;
}
}
}
double calcPriceForPerson(int countGuest) {
return total / (double) countGuest;
}
String getRubleAddition(double moneyValue) {
int preLastDigit = (int)moneyValue % 100 / 10;
if (preLastDigit == 1) {
return "рублей";
}
int LastDigit = (int)moneyValue % 10;
switch (LastDigit) {
case 1:
return "рубль";
case 2:
case 3:
case 4:
return "рубля";
default:
return "рублей";
}
}
}