forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFriends.java
More file actions
38 lines (33 loc) · 1.03 KB
/
Friends.java
File metadata and controls
38 lines (33 loc) · 1.03 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
import java.util.Scanner;
public class Friends {
int friendsCount;
void addItems() {
Scanner scanner = new Scanner(System.in);
System.out.println("На скольких человек необходимо разделить счёт?");
while (true) {
if (addFriend(scanner)) {
break;
}
}
}
boolean addFriend(Scanner scanner) {
if (!checkFormat(scanner)) {
System.out.println("Нужно указать число.");
scanner.next();
return false;
}
int friendsCount = scanner.nextInt();
if (!checkCount(friendsCount)) {
System.out.println("Укажите количество больше одного");
return false;
}
this.friendsCount = friendsCount;
return true;
}
boolean checkFormat(Scanner scanner) {
return scanner.hasNextInt();
}
boolean checkCount(int friendsCount) {
return friendsCount > 1;
}
}