Repository navigation
Expand file tree
/
Copy pathCaltulator.java
More file actions
46 lines (41 loc) · 1.96 KB
/
Copy pathCaltulator.java
File metadata and controls
46 lines (41 loc) · 1.96 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
import java.util.Scanner;
public class Caltulator {
Scanner in = new Scanner(System.in);
String namesDishes = "";
Float sumOfDishes = 0.00f;
Dish dish = new Dish();
void getDish(int countOfPersons) {
while (true) {
String needToContinue;
System.out.println("Введите название блюда");
dish.nameOfDish = in.nextLine();
namesDishes = namesDishes + dish.nameOfDish + "\n";
System.out.println("Введите цену блюда");
while (true) {
while (!in.hasNextFloat()) {
System.out.println("Ошибочка!");
System.out.println("Введите повторно");
in.next();
}
dish.priceOfDish = in.nextFloat();
if (dish.priceOfDish > 0) break;
else {
System.out.println("Введено некорректное значение! Попробуйте снова!");
while (!in.hasNextFloat()) {
System.out.println("Ошибочка!");
System.out.println("Введите повторно");
in.next();
}
}
}
sumOfDishes = sumOfDishes + dish.priceOfDish;
System.out.println("Блюдо успешно добавлено!\nВвести новое блюдо?");
needToContinue = in.nextLine();
needToContinue = in.nextLine();
if (needToContinue.equalsIgnoreCase("завершить")) break;
}
System.out.println("Добавленные товары: \n" + namesDishes);
String formatRubles = Formatter.toFormat(sumOfDishes/countOfPersons);
System.out.println("Каждый должен заплатить: " + String.format("%.2f", sumOfDishes/countOfPersons) + formatRubles);
}
}