From b69c7b3b9000c46a38180d51a483ec637f8e49e0 Mon Sep 17 00:00:00 2001 From: Jordan Elderidge Date: Mon, 12 Feb 2018 06:34:18 -0500 Subject: [PATCH 1/2] it is blank --- .../java/com/zipcodewilmington/looplabs/DuplicateDeleter.java | 2 ++ 1 file changed, 2 insertions(+) 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 From 7d313ab776140a65c8bcd3e5c324f6528589a129 Mon Sep 17 00:00:00 2001 From: Jordan Elderidge Date: Thu, 15 Feb 2018 17:22:25 -0500 Subject: [PATCH 2/2] done --- .../looplabs/IntegerDuplicateDeleter.java | 49 ++++++++++++++++++ .../looplabs/StringDuplicateDeleter.java | 50 +++++++++++++++++++ 2 files changed, 99 insertions(+) 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; + } } +