#13 completed duplicate deleter

Open
sambhutani wants to merge 1 commits from sambhutani/CR-MesoLabs-OOP-DuplicateDeleter:master into master

+ 48
- 0
src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java View File

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

+ 44
- 0
src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java View File

@@ -1,8 +1,52 @@
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
+        String[] resultArray= new String[array.length];
17
+        Integer count=0;
18
+        for(Integer i=0;i<array.length;i++){
19
+            if(itemcount(array[i]) < maxNumberOfDuplications){
20
+                resultArray[count]=array[i];
21
+                count++;
22
+            }
23
+        }
24
+        return Arrays.copyOfRange(resultArray,0,count);
25
+    }
26
+
27
+    @Override
28
+    public String[] removeDuplicatesExactly(int exactNumberOfDuplications) {
29
+        String[] resultArray= new String[array.length];
30
+        int count=0;
31
+        for(Integer i=0;i<array.length;i++){
32
+            if(itemcount(array[i])!= exactNumberOfDuplications){
33
+                resultArray[count]=array[i];
34
+                count++;
35
+
36
+            }
37
+        }
38
+        return Arrays.copyOfRange(resultArray,0,count);
39
+    }
40
+
41
+
42
+
43
+    public int itemcount(String value){
44
+        int count=0;
45
+        for(String element:array){
46
+            if(element.equals(value)){
47
+                count++;
48
+            }
49
+        }
50
+        return count;
51
+    }
8 52
 }