Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
52 lines (46 loc) · 1.73 KB
/
Copy pathMain.java
File metadata and controls
52 lines (46 loc) · 1.73 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
Scanner scanner = new Scanner(System.in);
String input = "";
int peopleCount = -1;
while (peopleCount <= 0 ) {
System.out.println("Введите количество гостей");
try {
input = scanner.nextLine();
peopleCount = Integer.parseInt(input);
} catch (Exception error) {
System.out.println("Пожалуйста введите корректное значение");
}
}
System.out.println("Количество человек " + peopleCount);
ProductAndPrice productAndPrice = new ProductAndPrice();
productAndPrice.Calc();
double everyCheck = productAndPrice.calculator / peopleCount;
System.out.println("Каждому нужно заплатить " + String.format("%.2f", everyCheck) + " " + detectSuffix(everyCheck) + ".");
System.out.println(productAndPrice.nameProduct);
}
public static String detectSuffix(double everyCheck) {
String rub = "";
int sumCheck1 = (int) ((Math.floor(everyCheck))%10);
switch (sumCheck1) {
case 1:
rub = "Рубль";
break;
case 2:
case 3:
case 4:
rub = "Рубля";
break;
default:
rub = "Рублей";
break;
}
int sumCheck2 = (int) ((Math.floor(everyCheck))%100);
if (11 <= sumCheck2 & sumCheck2 <= 19) {
rub = "Рублей";
}
return rub;
}
}