Browse Source

arrAnalyz 11 - 11

tictactoe 21 - 21
waveGener 10 - 10
collectio 0
pigLatin  09 - 12
Generics  06 - 18
Total     89 - 108
Nick Satinover 6 years ago
parent
commit
d73f4cdec8
1 changed files with 25 additions and 2 deletions
  1. 25
    2
      src/main/java/rocks/zipcode/io/quiz3/generics/ArrayUtility.java

+ 25
- 2
src/main/java/rocks/zipcode/io/quiz3/generics/ArrayUtility.java View File

1
 package rocks.zipcode.io.quiz3.generics;
1
 package rocks.zipcode.io.quiz3.generics;
2
 
2
 
3
+import java.util.ArrayList;
4
+import java.util.Arrays;
5
+import java.util.HashSet;
3
 import java.util.function.Function;
6
 import java.util.function.Function;
4
 
7
 
5
 /**
8
 /**
13
     }
16
     }
14
 
17
 
15
     public SomeType findOddOccurringValue() {
18
     public SomeType findOddOccurringValue() {
16
-        return null;
19
+        return findnNumberOccurringValue(1);
17
     }
20
     }
18
 
21
 
19
     public SomeType findEvenOccurringValue() {
22
     public SomeType findEvenOccurringValue() {
20
-        return null;
23
+        return findnNumberOccurringValue(0);
21
     }
24
     }
22
 
25
 
23
     public Integer getNumberOfOccurrences(SomeType valueToEvaluate) {
26
     public Integer getNumberOfOccurrences(SomeType valueToEvaluate) {
35
     public SomeType[] filter(Function<SomeType, Boolean> predicate) {
38
     public SomeType[] filter(Function<SomeType, Boolean> predicate) {
36
         return null;
39
         return null;
37
     }
40
     }
41
+
42
+    public SomeType findnNumberOccurringValue(int evenOrOdd) {
43
+        Arrays.sort(array);
44
+        int currentCount;
45
+        SomeType returnValue = null;
46
+
47
+        for (int i = 0; i < array.length; i++) {
48
+            currentCount = 0;
49
+            for (int j = 0; j < array.length; j++) {
50
+                if (array[j] == array[i]){
51
+                    currentCount++;
52
+                }
53
+            }
54
+            if (currentCount % 2 == evenOrOdd){
55
+                return array[i];
56
+            }
57
+        }
58
+
59
+        return returnValue;
60
+    }
38
 }
61
 }