forked from Yandex-Practicum/Java-Module-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
61 lines (54 loc) · 2.29 KB
/
Calculator.java
File metadata and controls
61 lines (54 loc) · 2.29 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
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
public class Calculator {
List<String> menuList = new LinkedList<>();
String stopWord = "завершить";
String dishes;
double price;
static double priceSum;
public void costCalculator() {
while (true) {
Scanner scanner = new Scanner(System.in);
System.out.println("Введите название еды:");
dishes = scanner.nextLine();
menuList.add(dishes);
System.out.println("Введите стоимость в формате: \"'рубли.копейки' [10,45; 11,40]\"");
while (!scanner.hasNextDouble()) {
System.out.println("Вводить нужно только цифры! Попробуйте заново:");
scanner.nextLine();
}
price = scanner.nextDouble();
if (price > 0) {
priceSum = priceSum + price;
System.out.println("Товар успешно добавлен! ");
}
while (price <= 0) {
if (price <= 0) {
System.out.println("Цена отрицательная, доходы мы еще не считаем! Введите заново: ");
price = scanner.nextDouble();
if (price > 0) {
priceSum = priceSum + price;
System.out.println("Товар успешно добавлен! ");
break;
}
}
}
System.out.println("Если хотите продолжить введите - любой символ,если хотите остановиться введите 'завершить' ");
dishes = scanner.next();
if (dishes.equalsIgnoreCase(stopWord)) {
break;
}
}
}
static String costRounding(double i) {
i = Math.floor(i);
double modularDivision = i % 10;
if (modularDivision == 1) {
return "рубль";
} else if (modularDivision == 2 || modularDivision == 3 || modularDivision == 4) {
return "рубля";
}
return "рублей";
}
}