forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScaner.java
More file actions
34 lines (32 loc) · 1.45 KB
/
Scaner.java
File metadata and controls
34 lines (32 loc) · 1.45 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
import java.util.Scanner;
public class Scaner {
public static void scaner(){
Scanner scanner = new Scanner(System.in);
scanner.useDelimiter("\n");
int guests;
System.out.println("Здраствуйте!\nНа сколько человек необходимо разделить счет?");
while (true) {
if (scanner.hasNextInt()) {
guests = scanner.nextInt();
if (guests == 1) {
System.out.println("Вы один. В этом случае нет смысла ничего считать и делить.");
} else if (guests <= 1) {
System.out.println("Это некорректное значение для подсчёта.");
} else if (guests >= 1) {
System.out.println("Включаем калькулятор товаров!");
break;
}
} else {
System.out.println("Это неправильное число!");
scanner.next();
}
}
Calculator calculator = new Calculator();
calculator.sumProduct();
System.out.println(calculator.allProduct);
double totalCost = calculator.sum / guests;
Formatter formatter = new Formatter();
formatter.rightFormat(totalCost);
System.out.println("Счет поделен на: " + guests + " гостей. " + "С каждого по " + formatter.rightFormat(totalCost) + ".");
}
}