forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
57 lines (50 loc) · 2.37 KB
/
Main.java
File metadata and controls
57 lines (50 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
import java.util.Scanner;
public class Main {
static Scanner scanner = new Scanner(System.in); //Добавляем сканер длядальнейшего использования в методах.
static String items = "";
static double sum = 0;
static int quantity=0;
public static void main(String[] args) {
int numberOfPeople = People.howMuchPeople();
whatInBill();
double personalCost = sum/numberOfPeople;
String rub = CorrectRub.getFormatRub();
printResult (personalCost, rub);
}
public static void whatInBill() {
StringBuilder builder = new StringBuilder();
System.out.println("Ну, и что ели?");
while (true) {
String input = scanner.nextLine();
if (input.equalsIgnoreCase("Завершить")) {
System.out.println("Фух! Я надеюсь вы не лопните...");
break;
}
builder.append(items+input).append("\n");
System.out.println("А сколько стоило?");
double price;
while (true) {
if (scanner.hasNextDouble()) {
price = scanner.nextDouble();
if (price < 0) {
System.out.println("Серьезно, покормили и денег дали? Давай еще раз...");
} else {
sum = price + sum;//Считаем стоимость товаров
System.out.println("Товар добавлен, общая сумма: " + sum + " руб. Что еще добавить из блюд? Если ничего, напиши 'Завершить'");
break;
}
} else {
System.out.println("Не шути со мной, кожанный, у тебя последняя попытка");
scanner.nextLine();
}
}
scanner.nextLine();
}
items=builder.toString();
}
static void printResult(double personalCost, String rub) {
System.out.println("Добавленные товары: ");
System.out.print(items);
System.out.printf("Короче, клоуны, с каждого к оплате: %.2f %s", personalCost, rub);
}
}