forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
73 lines (60 loc) · 2.48 KB
/
Calculator.java
File metadata and controls
73 lines (60 loc) · 2.48 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
62
63
64
65
66
67
68
69
70
import java.util.Scanner;
public class Calculator {
boolean check;
String allProduct = "";
float totalPrice;
float costPerPeople;
void allNames(String nextProduct) {
allProduct = allProduct + "\n" + nextProduct;
}
void fullPrice(float nextCost) {
totalPrice = totalPrice + nextCost;
}
void calcPerPeople(int people) {
costPerPeople = totalPrice / people;
}
void finalOut() {
Calculator calculator = new Calculator();
String end;
if (costPerPeople < 2) end = "бль";
else if (costPerPeople > 2 && costPerPeople < 5) end = "бля";
else end = "блей";
String finalOut = "Добавленные товары:%s\nКаждый человек должен заплатить %.2f ру%s.";
String finalOutput = String.format(finalOut, allProduct, costPerPeople, end);
System.out.println(finalOutput);
}
void calc() {
Product prod = new Product();
Scanner scanner = new Scanner(System.in);
System.out.println("На скольких человек необходимо разделить счёт?");
int people = 0;
while (true) {
people = scanner.nextInt();
if (people > 1) {
break;
} else {
System.out.println("Введите корректное количество гостей");
}
}
while (true) {
System.out.println("Введите название товара или завершить");
prod.name = scanner.next();
if (prod.name.equalsIgnoreCase("завершить")) {
break;
} else {
while (true) {
System.out.println("Введите стоимость (Стоимость должна быть в формате рубли.копейки, например 10.45 или 11.40):");
prod.cost = scanner.nextFloat();
if (prod.cost > 0) {
System.out.println("Товар " + prod.name + " стоимостью " + prod.cost + " успешно добавлен. \nХотите добавить ещё один товар?");
allNames(prod.name);
fullPrice(prod.cost);
break;
}
}
}
}
calcPerPeople(people);
finalOut();
}
}