Sfoglia il codice sorgente

Passing all the test.

William Brown 6 anni fa
parent
commit
48fd5439bf

+ 54
- 1
src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java Vedi File

@@ -1,8 +1,61 @@
1 1
 package com.zipcodewilmington.looplabs;
2 2
 
3
+import java.lang.reflect.Array;
4
+import java.util.Arrays;
5
+
3 6
 /**
4 7
  * Created by leon on 1/29/18.
5 8
  * @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
6 9
  */
7 10
 public final class IntegerDuplicateDeleter extends DuplicateDeleter<Integer> {
8
-}
11
+    public IntegerDuplicateDeleter(Integer[] intArray) {
12
+        super(intArray);
13
+    }
14
+
15
+    @Override
16
+    public Integer[] removeDuplicates(int maxNumberOfDuplications) {
17
+        Integer[] dupes = countDuplicates();
18
+        Integer[] noDupes = new Integer[this.array.length];
19
+        int count = 0;
20
+
21
+        for(int i = 0; i < dupes.length; i++){
22
+            if(dupes[i] < maxNumberOfDuplications){
23
+                noDupes[count] = this.array[i];
24
+                count++;
25
+            }
26
+        }
27
+
28
+        return Arrays.copyOfRange(noDupes, 0, count);
29
+    }
30
+
31
+    @Override
32
+    public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) {
33
+        Integer[] dupes = countDuplicates();
34
+        Integer[] noDupes = new Integer[this.array.length];
35
+        int count = 0;
36
+
37
+        for(int i = 0; i < dupes.length; i++){
38
+            if(dupes[i] != exactNumberOfDuplications){
39
+                noDupes[count] = this.array[i];
40
+                count++;
41
+            }
42
+        }
43
+
44
+        return Arrays.copyOfRange(noDupes, 0, count);
45
+    }
46
+
47
+    public Integer[] countDuplicates(){
48
+        Integer[] dupes = new Integer[this.array.length];
49
+        Arrays.fill(dupes, 0);
50
+
51
+        for(int i = 0; i < this.array.length; i++){
52
+            for(int j = 0; j < this.array.length; j++){
53
+                if(this.array[i].equals(this.array[j])){
54
+                    dupes[i]++;
55
+                }
56
+            }
57
+        }
58
+
59
+        return dupes;
60
+    }
61
+}

+ 52
- 0
src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java Vedi File

@@ -1,8 +1,60 @@
1 1
 package com.zipcodewilmington.looplabs;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 /**
4 6
  * Created by leon on 1/28/18.
5 7
  * @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
6 8
  */
7 9
 public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
10
+    public StringDuplicateDeleter(String[] intArray) {
11
+        super(intArray);
12
+    }
13
+
14
+    @Override
15
+    public String[] removeDuplicates(int maxNumberOfDuplications) {
16
+        Integer[] dupes = countDuplicates();
17
+        String[] noDupes = new String[this.array.length];
18
+        int count = 0;
19
+
20
+        for(int i = 0; i < dupes.length; i++){
21
+            if(dupes[i] < maxNumberOfDuplications){
22
+                noDupes[count] = this.array[i];
23
+                count++;
24
+            }
25
+        }
26
+
27
+        return Arrays.copyOfRange(noDupes, 0, count);
28
+    }
29
+
30
+    @Override
31
+    public String[] removeDuplicatesExactly(int exactNumberOfDuplications) {
32
+        Integer[] dupes = countDuplicates();
33
+        String[] noDupes = new String[this.array.length];
34
+        int count = 0;
35
+
36
+        for(int i = 0; i < dupes.length; i++){
37
+            if(dupes[i] != exactNumberOfDuplications){
38
+                noDupes[count] = this.array[i];
39
+                count++;
40
+            }
41
+        }
42
+
43
+        return Arrays.copyOfRange(noDupes, 0, count);
44
+    }
45
+
46
+    public Integer[] countDuplicates(){
47
+        Integer[] dupes = new Integer[this.array.length];
48
+        Arrays.fill(dupes, 0);
49
+
50
+        for(int i = 0; i < this.array.length; i++){
51
+            for(int j = 0; j < this.array.length; j++){
52
+                if(this.array[i].equals(this.array[j])){
53
+                    dupes[i]++;
54
+                }
55
+            }
56
+        }
57
+
58
+        return dupes;
59
+    }
8 60
 }

+ 4
- 0
src/test/java/com/zipcodewilmington/looplabs/CountDupTest.java Vedi File

@@ -0,0 +1,4 @@
1
+package com.zipcodewilmington.looplabs;
2
+
3
+public class CountDupTest {
4
+}