-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
111 lines (101 loc) · 3.02 KB
/
Main.java
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
101
102
103
104
105
106
107
108
109
110
111
package hw10;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import lessons10.Person;
public class Main {
public static void main(String[] args) {
List<Commodity> com = new ArrayList<Commodity>();
System.out.println("Äëÿ ïåðåõîäó äî ïîòð³áíî¿ âàì 䳿 ââåä³òü öèôðó: ");
System.out.println("");
System.out.println("1) Äîäàòè òîâàð.");
System.out.println("2)Âèäàëèòè òîâàð.");
System.out.println("3)Çàì³íèòè òîâàð.");
System.out.println("4)Âèâåñòè ³ ñîðòóâàòè òîâàð çà íàçâîþ.");
System.out.println("5)Âèâåñòè ³ ñîðòóâàòè òîâàð çà ö³íîþ.");
System.out.println("6)Âèâåñòè ³ ñîðòóâàòè òîâàð çà ê³ëüê³ñòþ.");
System.out.println("7)Âèéòè ç ïðîãðàìè.");
System.out.println("");
com.add(new Commodity("Bear",30,45));
com.add(new Commodity("milk",15,6));
com.add(new Commodity("meat",70,30));
com.add(new Commodity("cheeze",90,40));
com.add(new Commodity("oil",25,37));
System.out.println(com);
boolean col=true;
while(col) {
Scanner sc = new Scanner(System.in);
// System.out.println("Number");
int number = sc.nextInt();
switch(number) {
case 1:{
System.out.println("Ââåä³òü íàçâó òîâàðó: ");
String name = sc.next();
System.out.println("Ââåä³òü ö³íó òîâàðó: ");
int price = sc.nextInt();
System.out.println("Ââåä³òü ê³ëüê³ñòü òîâàðó: ");
int amount = sc.nextInt();
com.add(new Commodity(name,price,amount));
System.out.println(com);
break;
}
case 2:{
System.out.println("Ââåä³òü íàçâó òîâàðó äëÿ âèäàëåííÿ: ");
Iterator<Commodity> iter =com.iterator();
String name = sc.next();
while(iter.hasNext()){
if(iter.next().getName().equals(name)) {
iter.remove();
}
}
System.out.println(com);
break;
}
case 3:{
System.out.println("Ââåä³òü íàçâó òîâàðó , ÿêèé áàæàºòå çàì³íèòè: ");
Iterator<Commodity> iter =com.iterator();
String name = sc.next();
while(iter.hasNext()){
if(iter.next().getName().equals(name)) {
iter.remove();
}
}
System.out.println("Ââåä³òü íàçâó íîâîãî òîâàðó: ");
String name1 = sc.next();
System.out.println("Ââåä³òü ö³íó íîâîãî òîâàðó: ");
int price = sc.nextInt();
System.out.println("Ââåä³òü ê³ëüê³ñòü íîâîãî òîâàðó: ");
int amount = sc.nextInt();
com.add(new Commodity(name1,price,amount));
System.out.println(com);
break;
}
case 4:{
com.sort(new SortByName());
System.out.println(com);
break;
}
case 5:{
com.sort(new SortByPrice());
System.out.println(com);
break;
}
case 6:{
com.sort(new SortByAmount());
System.out.println(com);
break;
}
case 7:{
col=false;
System.out.println("EXIT");
break;
}
default :{
System.out.println("Ââåäåíà íåêîðåêòíà öèôðà!!!");
break;
}
}
}
}
}