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
53 lines (44 loc) · 1.69 KB
/
Main.java
File metadata and controls
53 lines (44 loc) · 1.69 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Приветствую!\nНа сколько персон желаете разделить счёт ?");
int numberPerson = checkNumberPersons();
Dish dish = new Dish();
System.out.println(dish.addDish());
float paymentPerson = dish.allCost / (float) numberPerson;
System.out.printf("К оплате с каждой персоны: %.2f " + rublesCases(dish.allCost, numberPerson), paymentPerson);
}
public static int checkNumberPersons() {
Scanner scanner = new Scanner(System.in);
int numberPerson;
while (true) {
if (scanner.hasNextInt()) {
numberPerson = Integer.parseInt(scanner.nextLine());
if (numberPerson <= 1) {
System.out.println("Некорректное значение");
} else {
break;
}
} else {
System.out.println("ОШИБКА!\nНекорректное значение");
scanner.nextLine();
}
}
return numberPerson;
}
public static String rublesCases(float cost, int numberPerson) {
float allRubles = cost / numberPerson;
int ruble = (int) (allRubles % 100);
String cases;
if (ruble == 1) {
cases = "рубль";
} else if (ruble >= 2 && ruble <= 4) {
cases = "рубля";
} else if (ruble >= 11 && ruble <= 14) {
cases = "рублей";
} else {
cases = "рублей";
}
return cases;
}
}