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
55 lines (53 loc) · 1.95 KB
/
Main.java
File metadata and controls
55 lines (53 loc) · 1.95 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
calculateIt();
}
public static void calculateIt (){
int human=0;
while(human<=1){
human=checkPeople ();
}
Calc clc = new Calc();
clc.askAboutThings();
System.out.println("Добавленные товары:");
System.out.println(clc.nameOfThings);
float delSum= (clc.sum/human);
int sumWithoutReal = (int)delSum;
String formatTmp;
if (sumWithoutReal%100>10&&sumWithoutReal%100<20){
formatTmp = "Каждый должен заплатить %.2f рублей";
}
else if (sumWithoutReal%10==1) {
formatTmp = "Каждый должен заплатить %.2f рубль";
}
else if (sumWithoutReal%10>1&&sumWithoutReal%10<5) {
formatTmp = "Каждый должен заплатить %.2f рубля";
}
else {
formatTmp = "Каждый должен заплатить %.2f рублей";
}
System.out.println(String.format(formatTmp,delSum));
}
public static int checkPeople (){
Scanner scanner = new Scanner(System.in);
System.out.println("На скольких человек необходимо разделить счёт?");
int userInput;
while (true){
if (!scanner.hasNextInt()) {
System.out.println("Введите корректное количество людей в штуках");
scanner.next();
}
else{
userInput = scanner.nextInt();
if(userInput<=1){
System.out.println("Число людей должно быть больше одного");
}
else{
break;
}
}
}
return userInput;
}
}