forked from Yandex-Practicum/Java-Module-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
61 lines (44 loc) · 2.37 KB
/
Main.java
File metadata and controls
61 lines (44 loc) · 2.37 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 Main {
public static void main(String[] args) {
int persons;
String foodName;
double foodCost;
String totalFoodList;
double totalCost;
String statement;
while (true) {
System.out.println("Введите количество участников");
Scanner input = new Scanner(System.in);
if (input.hasNextInt()) {
persons = input.nextInt();
if (persons <= 0) {System.out.println("Количество участников отрицательно или равно нулю. Попробуйте еще раз.");}
else if (persons == 1) {System.out.println("Нет необходимости делить счет");}
else if (persons >0) {break;}
}
else {System.out.println("Вы ввели неверные данные. Попробуйте еще раз.");}
}
Calculator calculating = new Calculator();
while (true) {
Scanner dishesInput = new Scanner (System.in);
System.out.println("Что Вы с друзями заказали ?");
foodName = dishesInput.next();
totalFoodList = calculating.foodNameConcat(foodName);
System.out.println("Сколько стоило это блюдо ?");
if (dishesInput.hasNextDouble()) {
foodCost = dishesInput.nextDouble();
totalCost = calculating.foodCostCalc(persons,foodCost);
System.out.println("Это все ? Завершить/Нет");
statement = dishesInput.next();
if (statement.equalsIgnoreCase("Завершить")) {
break;
}
}
else {System.out.println("Что-то не так со стоимостью блюда. Попробуйте еще раз.");}
}
Check cur = new Check();
System.out.println("Ваш заказ: " + "\n" + totalFoodList);
System.out.println("Ваш общий счет: " + String.format("%,.2f", totalCost) + " " + cur.currencyAddition(totalCost) );
System.out.println("Каждый должен оплатить " + String.format("%,.2f", (totalCost/persons)) + " " + cur.currencyAddition(totalCost/persons));
}
}