Ver código fonte

all tests pass

mpierse 6 anos atrás
pai
commit
b4657384f7

+ 9
- 1
src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java Ver arquivo

@@ -5,7 +5,7 @@ import rocks.zipcode.io.quiz3.objectorientation.enums.LabStatus;
5 5
 /**
6 6
  * @author leon on 10/12/2018.
7 7
  */
8
-public class Lab {
8
+public class Lab implements Comparable {
9 9
 
10 10
     String name;
11 11
     String labStatus;
@@ -38,4 +38,12 @@ public class Lab {
38 38
     public String getName() {
39 39
         return this.name;
40 40
     }
41
+
42
+    @Override
43
+    public int compareTo(Object o) {
44
+        Lab obj = (Lab) o;
45
+        if(this.getName().charAt(0)> obj.getName().charAt(0)) return -1;
46
+        return 1;
47
+
48
+    }
41 49
 }

+ 6
- 2
src/main/java/rocks/zipcode/io/quiz3/collections/Student.java Ver arquivo

@@ -41,14 +41,18 @@ public class Student {
41 41
                 return map.get(l);
42 42
             }
43 43
         }
44
-        throw new UnsupportedOperationException("Method not yet implemented");
44
+       // throw new UnsupportedOperationException("Method not yet implemented");
45
+        return null;
45 46
     }
46 47
 
47 48
     @Override
48 49
     public String toString(){
49 50
         String result = "";
50 51
         for (Lab l: map.keySet()) {
51
-            result = l.getName() + " > " + getLabStatus(l.getName()) + "\n" + result;
52
+            if(result.equals("")){result=l.getName() + " > " + getLabStatus(l.getName()) + "\n";}
53
+            else if (l.getName().charAt(0)<result.charAt(0))
54
+            {result = l.getName() + " > " + getLabStatus(l.getName()) + "\n" + result;}
55
+            else {result += l.getName() + " > " + getLabStatus(l.getName()) + "\n";}
52 56
         }
53 57
         return result.substring(0, result.length()-1);
54 58
     }

+ 17
- 2
src/main/java/rocks/zipcode/io/quiz3/generics/ArrayUtility.java Ver arquivo

@@ -1,5 +1,6 @@
1 1
 package rocks.zipcode.io.quiz3.generics;
2 2
 
3
+import java.util.Arrays;
3 4
 import java.util.function.Function;
4 5
 
5 6
 /**
@@ -13,18 +14,32 @@ public class ArrayUtility<SomeType> {
13 14
     }
14 15
 
15 16
     public SomeType findOddOccurringValue() {
17
+        for (SomeType thing: array) {
18
+            if(getNumberOfOccurrences(thing)%2==1) return thing;
19
+        }
16 20
         return null;
17 21
     }
18 22
 
19 23
     public SomeType findEvenOccurringValue() {
24
+        for (SomeType thing: array) {
25
+            if(getNumberOfOccurrences(thing)%2==0) return thing;
26
+        }
20 27
         return null;
21 28
     }
22 29
 
23 30
     public Integer getNumberOfOccurrences(SomeType valueToEvaluate) {
24
-        return null;
31
+        Integer i = 0;
32
+        for (SomeType thing: array) {
33
+            if(thing.equals(valueToEvaluate)) i++;
34
+        }
35
+        return i;
25 36
     }
26 37
 
27 38
     public SomeType[] filter(Function<SomeType, Boolean> predicate) {
28
-        return null;
39
+
40
+        Class classDeclare = array[0].getClass().getComponentType();
41
+        SomeType[] arr =  (SomeType[]) Arrays.stream(array).map(predicate).toArray();
42
+
43
+        return arr;
29 44
     }
30 45
 }