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
49 lines (43 loc) · 1.84 KB
/
Main.java
File metadata and controls
49 lines (43 loc) · 1.84 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
import java.util.ArrayList;
import java.util.Scanner;
// dev branch for Y.Practicum
public class Main {
public static void main(String[] args) {
Double price;
String name;
ArrayList<Dish> dishesList = new ArrayList<>();
int personCount = getPersonCount();
Scanner scanner = new Scanner(System.in);
String line = "";
while(true){
dishesList.add(new Dish());
System.out.println("Для добавления нового товара введите что угодно. Для завершения введите 'завершить'");
line = scanner.nextLine();
if(line.equalsIgnoreCase("завершить")){
System.out.println("Составление списка успешно завершино");
break;
}
}
Calculator calculator = new Calculator(personCount, dishesList);
}
private static int getPersonCount(){
Scanner scanner;
while(true){
System.out.println("На скольких человек необходимо разделить счёт?");
scanner = new Scanner(System.in);
if(!scanner.hasNextInt()){
System.out.println("Нужно целое число без букв. Попробуйте снова");
continue;
}
int personCount = scanner.nextInt();
if(personCount < 2){
System.out.println("Число персон должно быть не меньше двух. Попробуйте снова");
continue;
}
else{
System.out.println("Счёт будет разделён на " + personCount + " персоны");
return personCount;
}
}
}
}