diff --git a/src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleter.java b/src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleter.java index c176838..5787675 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleter.java @@ -12,4 +12,6 @@ public DuplicateDeleter(T[] intArray) { abstract public T[] removeDuplicates(int maxNumberOfDuplications); abstract public T[] removeDuplicatesExactly(int exactNumberOfDuplications); + + // I did not get a chance to get around to this... } \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java b/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java index ee550c5..d866ebc 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java @@ -1,8 +1,57 @@ package com.zipcodewilmington.looplabs; +import java.util.Arrays; + /** * Created by leon on 1/29/18. * @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class. */ public final class IntegerDuplicateDeleter extends DuplicateDeleter { + + + public IntegerDuplicateDeleter(Integer[] intArray) { + super(intArray); + } + + @Override + public Integer[] removeDuplicates(int maxNumberOfDuplications) { + Integer[] removeDupExact = new Integer[0]; + for (int i =0; i < this.array.length; i++){ + if (getNumberOfOccurrences(this.array,this.array[i]) < maxNumberOfDuplications){ + int element = removeDupExact.length; + removeDupExact = Arrays.copyOf(removeDupExact,removeDupExact.length +1); + removeDupExact[element] = this.array[i]; + } + + } + + return removeDupExact; + } + + @Override + public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) { + Integer[] removeDupExact = new Integer[0]; + for (int i =0; i < this.array.length; i++){ + if (getNumberOfOccurrences(this.array,this.array[i])!= exactNumberOfDuplications){ + int element = removeDupExact.length; + removeDupExact = Arrays.copyOf(removeDupExact,removeDupExact.length +1); + removeDupExact[element] = this.array[i]; + } + + } + + return removeDupExact; + + + } + public int getNumberOfOccurrences (Integer[]array,Integer value) { + int counter = 0; + for (int i = 0; i < array.length; i++) { + if (array[i].equals(value)) { + counter++; + } + } + return counter; + } + } diff --git a/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java b/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java index 4818fe3..ade5eca 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java @@ -1,8 +1,58 @@ package com.zipcodewilmington.looplabs; +import java.lang.reflect.Array; +import java.util.Arrays; + /** * Created by leon on 1/28/18. * @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class. */ public final class StringDuplicateDeleter extends DuplicateDeleter { + + + public StringDuplicateDeleter(String[] intArray) { + super(intArray); + } + + @Override + public String[] removeDuplicates(int maxNumberOfDuplications) { + String[] removeDupExact = new String[0]; + for (int i =0; i < this.array.length; i++){ + if (getNumberOfOccurrences(this.array,this.array[i]) < maxNumberOfDuplications){ + int element = removeDupExact.length; + removeDupExact = Arrays.copyOf(removeDupExact,removeDupExact.length +1); + removeDupExact[element] = this.array[i]; + } + + } + + return removeDupExact; + + + } + + @Override + public String[] removeDuplicatesExactly(int exactNumberOfDuplications) { + String[] removeDupExact = new String[0]; + for (int i =0; i < this.array.length; i++){ + if (getNumberOfOccurrences(this.array,this.array[i])!= exactNumberOfDuplications){ + int element = removeDupExact.length; + removeDupExact = Arrays.copyOf(removeDupExact,removeDupExact.length +1); + removeDupExact[element] = this.array[i]; + } + + } + + return removeDupExact; + } + public int getNumberOfOccurrences (String[]array,String value) { + int counter = 0; + for (int i = 0; i < array.length; i++) { + if (array[i].equals(value)) { + counter++; + } + } + return counter; + } } +