-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.java
More file actions
123 lines (113 loc) · 4.66 KB
/
Copy pathtask.java
File metadata and controls
123 lines (113 loc) · 4.66 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Map.Entry;
public class task{
public static void main(String[] args) {
laptop lap1=new laptop("A5",1236,"Xiaomi");
lap1.setColor("black");
lap1.setHDD(700);
lap1.setOS("Windows");
lap1.setRAM(8);
laptop lap2=new laptop("ABC30",6467,"Acer");
lap2.setColor("white");
lap2.setHDD(1000);
lap2.setOS("Windows");
lap2.setRAM(8);
laptop lap3=new laptop("AB97",67201,"Acer");
lap3.setColor("rose");
lap3.setHDD(900);
lap3.setOS("Windows");
lap3.setRAM(16);
laptop lap4=new laptop("OMAN11",1111,"hp");
lap4.setColor("black");
lap4.setHDD(700);
lap4.setOS("Linux");
lap4.setRAM(8);
laptop lap5=new laptop("MAC101",8438483,"Apple");
lap5.setColor("silver");
lap5.setHDD(1000);
lap5.setOS("macOS");
lap5.setRAM(8);
HashSet <laptop> laptops = new HashSet<>(Arrays.asList(lap1,lap2,lap3,lap4,lap5));
HashSet <laptop> res = new HashSet<>();
System.out.println("Здравствуйте");
System.out.print("Введите цифру, соответствующую необходимому критерию:\n 1 - ОЗУ \n 2 - Объем ЖД \n 3 - Операционная система \n 4 - цвет \n или 5, чтобы осуществить поиск\n");
Scanner sc = new Scanner(System.in);
Integer n = sc.nextInt();
sc.nextLine();
HashMap<String, Object> filters = new HashMap<>();
while(n!=5){
if(n==1){
System.out.println("Введите минимальную оперативную память");
Integer temp = sc.nextInt();
sc.nextLine();
filters.put("RAM", temp);
}
if(n==2){
System.out.println("Введите минимальный объем ЖД" );
Integer temp = sc.nextInt();
sc.nextLine();
filters.put("HDD", temp);
}
if(n==3){
System.out.println("Введите ОС");
String temp = sc.nextLine();
filters.put("OS", temp);
}
if(n==4){
System.out.println("Введите цвет");
String temp = sc.nextLine();
filters.put("color", temp);
}
System.out.print("Введите цифру, соответствующую необходимому критерию:\n 1 - ОЗУ \n 2 - Объем ЖД \n 3 - Операционная система \n 4 - цвет \n или 5, чтобы осуществить поиск\n");
n = sc.nextInt();
sc.nextLine();
}
for (Entry<String, Object> entry : filters.entrySet()) {
if(entry.getKey().equals("RAM")){
Iterator it = laptops.iterator();
while(it.hasNext()){
laptop lap = (laptop) it.next();
if(lap.getRAM()>=(Integer)entry.getValue()){
res.add(lap);
}
}
}
if(entry.getKey().equals("HDD")){
Iterator it = laptops.iterator();
while(it.hasNext()){
laptop lap = (laptop)it.next();
if(lap.getHDD()>=(Integer)entry.getValue()){
res.add(lap);
}
}
}
if(entry.getKey().equals("OS")){
Iterator it = laptops.iterator();
while(it.hasNext()){
laptop lap = (laptop)it.next();
if(lap.getOS().equals(entry.getValue())){
res.add(lap);
}
}
}
if(entry.getKey().equals("color")){
Iterator it = laptops.iterator();
while(it.hasNext()){
laptop lap = (laptop)it.next();
if(lap.getColor().equals(entry.getValue())){
res.add(lap);
}
}
}
}
Iterator it = res.iterator();
while(it.hasNext()){
laptop lap = (laptop)it.next();
System.out.println(lap.toString());
System.out.println();
}
}}