/Users/johnr/Desktop/IA_14_-_Stage_P_Upload_all_2021-04-08/CS IA Shoe Reselling Aryan April 6th /src/SearchinNSortn.java |
1
2
3
4
5
6
7
8
9 @author
10
11 import java.util.Arrays;
12 import java.util.Collections;
13 import java.util.LinkedList;
14 public class SearchinNSortn {
15
16 public void NumSortSize(LinkedList<Shoes> shoes)
17 {
18 for (int i = 0; i < shoes.size() -1; i++)
19 {
20 int minIndex = i;
21 for (int j = i+1; j < shoes.size(); j++)
22 {
23 if (shoes.get(j).getSize() < shoes.get(minIndex).getSize())
24 {
25 minIndex = j;
26 }
27 }
28 if (minIndex != i)
29 {
30 Shoes temp = shoes.get(i);
31
32 shoes.set(i, shoes.get(minIndex));
33
34 shoes.set(minIndex, temp);
35 }
36 }
37 }
38
39 public void AlphabetSortName(LinkedList<Shoes> shoes)
40 {
41 Shoes temp;
42 for (int i = 0; i < shoes.size(); i++)
43 {
44 for (int j = i + 1; j < shoes.size(); j++) {
45 if (shoes.get(i).getName().compareTo(shoes.get(j).getName())>0)
46 {
47 temp = shoes.get(i);
48
49 shoes.set(i, shoes.get(j));
50
51 shoes.set(j, temp);
52 }
53 }
54 }
55 }
56
57 public void AlphabetSortBrand(LinkedList<Shoes> shoes)
58 {
59 Shoes temp;
60 for (int i = 0; i < shoes.size(); i++)
61 {
62 for (int j = i + 1; j < shoes.size(); j++) {
63 if (shoes.get(i).getBrand().compareTo(shoes.get(j).getBrand())>0)
64 {
65 temp = shoes.get(i);
66
67 shoes.set(i, shoes.get(j));
68
69 shoes.set(j, temp);
70 }
71 }
72 }
73 }
74
75 public void AlphabetSortCollaboration(LinkedList<Shoes> shoes)
76 {
77 Shoes temp;
78 for (int i = 0; i < shoes.size(); i++)
79 {
80 for (int j = i + 1; j < shoes.size(); j++) {
81 if (shoes.get(i).getCollaboration().compareTo(shoes.get(j).getCollaboration())>0)
82 {
83 temp = shoes.get(i);
84
85 shoes.set(i, shoes.get(j));
86
87 shoes.set(j, temp);
88 }
89 }
90 }
91 }
92
93
94 public void ProfitSort(LinkedList<Shoes> shoes)
95 {
96 for (int i = 0; i < shoes.size() -1; i++)
97 {
98 int minIndex = i;
99 for (int j = i+1; j < shoes.size(); j++)
100 {
101 double profitA = shoes.get(j).getSellingPrice() - shoes.get(j).getBuyingPrice();
102 double profitB = shoes.get(minIndex).getSellingPrice() - shoes.get(minIndex).getBuyingPrice();
103
104 if (profitA < profitB)
105 {
106 minIndex = j;
107 }
108 }
109 if (minIndex != i)
110 {
111 Shoes temp = shoes.get(i);
112
113 shoes.set(i, shoes.get(minIndex));
114
115 shoes.set(minIndex, temp);
116 }
117 }
118 }
119
120
121
122
123
124
125
126
127
128
129
130
131 public LinkedList<Shoes> SizeSearch(LinkedList<Shoes> inventory, double size)
132 {
133 LinkedList<Shoes> shoes = new LinkedList<Shoes>();
134
135 for(int i = 0; i < inventory.size(); i++)
136 {
137 if(inventory.get(i).getSize() == size)
138 {
139 shoes.add(inventory.get(i));
140 }
141 }
142
143 return shoes;
144 }
145
146 public LinkedList<Shoes> NameSearch(LinkedList<Shoes> inventory, String name)
147 {
148 LinkedList<Shoes> shoes = new LinkedList<Shoes>();
149
150 for(int i = 0; i < inventory.size(); i++)
151 {
152 if(inventory.get(i).getName().equals(name))
153 {
154 shoes.add(inventory.get(i));
155 }
156 }
157
158 return shoes;
159 }
160
161 public LinkedList<Shoes> BrandSearch(LinkedList<Shoes> inventory, String brand)
162 {
163 LinkedList<Shoes> shoes = new LinkedList<Shoes>();
164
165 for(int i = 0; i < inventory.size(); i++)
166 {
167 if(inventory.get(i).getName().equals(brand))
168 {
169 shoes.add(inventory.get(i));
170 }
171 }
172
173 return shoes;
174 }
175
176
177 public LinkedList<Shoes> CollaborationSearch(LinkedList<Shoes> inventory, String collaboration)
178 {
179 LinkedList<Shoes> shoes = new LinkedList<Shoes>();
180
181 for(int i = 0; i < inventory.size(); i++)
182 {
183 if(inventory.get(i).getName().equals(collaboration))
184 {
185 shoes.add(inventory.get(i));
186 }
187 }
188
189 return shoes;
190 }
191
192
193
194 public LinkedList<Shoes> GeneralSearch(LinkedList<Shoes> inventory, Shoes shoe)
195 {
196
197 LinkedList<Shoes> shoes = new LinkedList<Shoes>();
198
199 return shoes;
200 }
201
202
203
204
205 }
206