forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogik.java
More file actions
100 lines (90 loc) · 3.07 KB
/
Logik.java
File metadata and controls
100 lines (90 loc) · 3.07 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import java.util.ArrayList;
import java.util.Scanner;
public class Logik extends Rubl {
static int count = 0;
static ArrayList<Tovar> arr = new ArrayList<>();
static Scanner in ;
public static void inputParameters (){
in = new Scanner(System.in);
while(true){
System.out.println("Введите количество человек");
if(in.hasNextInt()){
count = in.nextInt();
if(count>1){
addingProducts();
break;
}else{
System.out.println("Некорректное количество человек");
}
}else{
System.out.println("Некорректный ввод");
in.next();
}
}
in.close();
}
public static void addingProducts(){
String inp = "";
in.nextLine();
while(!inp.equalsIgnoreCase("Завершить")){
System.out.println("Добавить новый товар ? Да||Завершить");
inp = in.nextLine();
if (inp.equalsIgnoreCase("да")){
addTovar();
in.nextLine();
}
else if (!inp.equalsIgnoreCase("Завершить")){
System.out.println("Некоректный ввод");
}
}
outputResults();
}
public static void addTovar(){
System.out.println("Введите название товара ");
String name = in.nextLine();
double wer = 0;
while (!(wer > 0)){
System.out.println("Введите корректную цену товара");
if (in.hasNextFloat()||in.hasNextInt()||in.hasNextDouble()){
wer = scan();
if(wer< 0){
System.out.println("Некорректная цена");
}
}
else{
System.out.println("Некоректный ввод");
in.next();
}
}
arr.add(new Tovar(name,wer));
System.out.println("Товар успешно добавлен");
}
public static void outputResults() {
System.out.println("Добавленные товары:");
double all = 0;
if (arr.isEmpty()){
System.out.println("Товаров нет");
}else {
for (Tovar no : arr) {
all += no.coast;
no.see();
}
}
double n = all/count;
Rubl out = new Rubl();
System.out.printf("Общая сумма %.2f %s\n",all ,out.rubel(all));
System.out.printf("С каждого человека по %.2f %s\n",n ,out.rubel(n));
}
public static double scan(){
if (in.hasNextInt()){
return in.nextInt();
}
if (in.hasNextDouble()){
return in.nextDouble();
}
if (in.hasNextFloat()){
return in.nextFloat();
}
return 0;
}
}