From 0f069b5d6a937dc8702d3c1998e81424ef854c06 Mon Sep 17 00:00:00 2001 From: CWinarski Date: Sun, 11 Feb 2018 20:55:17 -0500 Subject: [PATCH 1/2] Coding is Hard T-T --- .../looplabs/IntegerDuplicateDeleter.java | 69 +++++++++++++++++++ .../looplabs/StringDuplicateDeleter.java | 63 +++++++++++++++++ 2 files changed, 132 insertions(+) diff --git a/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java b/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java index ee550c5..3836902 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java @@ -1,8 +1,77 @@ 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[] removeDuplicatesExactly(int exactNumberOfDuplications) { + + Integer[] finalArray = new Integer[0]; + + for (int i = 0; i < this.array.length; i++){ + + if (getNumberOfOccurrences(this.array, this.array[i]) != exactNumberOfDuplications){ + + int actualElements = finalArray.length; + finalArray = Arrays.copyOf(finalArray, finalArray.length+1); + finalArray[actualElements] = this.array[i]; + + } + + } + + return finalArray; + } + + public static int getNumberOfOccurrences(Integer[] inputArray, Integer value) { + + int valueCounter = 0; + + for (int arrayElement : inputArray){ + + if (arrayElement == value){ + + valueCounter++; + } + + } + + return valueCounter; + } + + + @Override + public Integer[] removeDuplicates(int maxNumberOfDuplications) { + Integer[] actualArray = new Integer[0]; + + for (int i = 0; i < this.array.length; i++){ + + if (getNumberOfOccurrences(this.array, this.array[i]) < maxNumberOfDuplications){ + + int arrayElements = actualArray.length; + actualArray = Arrays.copyOf(actualArray, actualArray.length+1); + actualArray[arrayElements] = this.array[i]; + + } + + } + + return actualArray; + + } } + + diff --git a/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java b/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java index 4818fe3..94cfcd4 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java @@ -1,8 +1,71 @@ package com.zipcodewilmington.looplabs; +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[] removeDuplicatesExactly(int exactNumberOfDuplications) { + + String[] noStringDupsArray = new String[0]; + + for (int i = 0; i < this.array.length; i++){ + + if (getNumberOfOccurrences(this.array, this.array[i]) != exactNumberOfDuplications) { + + int stringElements = noStringDupsArray.length; + noStringDupsArray = Arrays.copyOf(noStringDupsArray, noStringDupsArray.length + 1); + noStringDupsArray[stringElements] = this.array[i]; + + } + + } + + return noStringDupsArray; + } + + public static int getNumberOfOccurrences(String[] inputArray, String value) { + + int valueCounter = 0; + + for (String arrayElement : inputArray){ + + if (arrayElement.equalsIgnoreCase(value)){ + + valueCounter++; + } + + } + + return valueCounter; + } + + + @Override + public String[] removeDuplicates(int maxNumberOfDuplications) { + String[] maxDupsArray = new String[0]; + + for (int i = 0; i < this.array.length; i++){ + + if (getNumberOfOccurrences(this.array, this.array[i]) < maxNumberOfDuplications){ + + int arrayElements = maxDupsArray.length; + maxDupsArray = Arrays.copyOf(maxDupsArray, maxDupsArray.length+1); + maxDupsArray[arrayElements] = this.array[i]; + + } + + } + + return maxDupsArray; + } } From b9f03b7301b5972fce353165ad0fb5f28e540472 Mon Sep 17 00:00:00 2001 From: CWinarski Date: Thu, 15 Feb 2018 17:49:31 -0500 Subject: [PATCH 2/2] Reformatted Files --- .../looplabs/DuplicateDeleter.java | 1 + .../looplabs/DuplicateDeleterInterface.java | 2 + .../looplabs/IntegerDuplicateDeleter.java | 26 +++++----- .../looplabs/RandomNumberFactory.java | 5 +- .../looplabs/StringDuplicateDeleter.java | 17 +++---- .../looplabs/IntegerDuplicateDeleterTest.java | 48 ++----------------- .../looplabs/StringDuplicateDeleterTest.java | 32 +------------ .../zipcodewilmington/looplabs/TestSuite.java | 1 + .../zipcodewilmington/looplabs/TestUtils.java | 1 + 9 files changed, 36 insertions(+), 97 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleter.java b/src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleter.java index c176838..7a9b3c5 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleter.java @@ -11,5 +11,6 @@ public DuplicateDeleter(T[] intArray) { } abstract public T[] removeDuplicates(int maxNumberOfDuplications); + abstract public T[] removeDuplicatesExactly(int exactNumberOfDuplications); } \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleterInterface.java b/src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleterInterface.java index 058f8f9..bd492d9 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleterInterface.java +++ b/src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleterInterface.java @@ -2,9 +2,11 @@ /** * Created by leon on 1/28/18. + * * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class. */ public interface DuplicateDeleterInterface { T[] removeDuplicates(int maxNumberOfDuplications); + T[] removeDuplicatesExactly(int exactNumberOfDuplications); } \ 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 3836902..f45a4a7 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java @@ -4,29 +4,28 @@ /** * 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); + public IntegerDuplicateDeleter(Integer[] intArray) { + super(intArray); } - - @Override public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) { - Integer[] finalArray = new Integer[0]; + Integer[] finalArray = new Integer[0]; - for (int i = 0; i < this.array.length; i++){ + for (int i = 0; i < this.array.length; i++) { - if (getNumberOfOccurrences(this.array, this.array[i]) != exactNumberOfDuplications){ + if (getNumberOfOccurrences(this.array, this.array[i]) != exactNumberOfDuplications) { int actualElements = finalArray.length; - finalArray = Arrays.copyOf(finalArray, finalArray.length+1); + finalArray = Arrays.copyOf(finalArray, finalArray.length + 1); finalArray[actualElements] = this.array[i]; } @@ -40,9 +39,9 @@ public static int getNumberOfOccurrences(Integer[] inputArray, Integer value) { int valueCounter = 0; - for (int arrayElement : inputArray){ + for (int arrayElement : inputArray) { - if (arrayElement == value){ + if (arrayElement == value) { valueCounter++; } @@ -57,12 +56,12 @@ public static int getNumberOfOccurrences(Integer[] inputArray, Integer value) { public Integer[] removeDuplicates(int maxNumberOfDuplications) { Integer[] actualArray = new Integer[0]; - for (int i = 0; i < this.array.length; i++){ + for (int i = 0; i < this.array.length; i++) { - if (getNumberOfOccurrences(this.array, this.array[i]) < maxNumberOfDuplications){ + if (getNumberOfOccurrences(this.array, this.array[i]) < maxNumberOfDuplications) { int arrayElements = actualArray.length; - actualArray = Arrays.copyOf(actualArray, actualArray.length+1); + actualArray = Arrays.copyOf(actualArray, actualArray.length + 1); actualArray[arrayElements] = this.array[i]; } @@ -72,6 +71,7 @@ public Integer[] removeDuplicates(int maxNumberOfDuplications) { return actualArray; } + } diff --git a/src/main/java/com/zipcodewilmington/looplabs/RandomNumberFactory.java b/src/main/java/com/zipcodewilmington/looplabs/RandomNumberFactory.java index 984cff6..24fa3e1 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/RandomNumberFactory.java +++ b/src/main/java/com/zipcodewilmington/looplabs/RandomNumberFactory.java @@ -11,6 +11,7 @@ public final class RandomNumberFactory { private RandomNumberFactory() { } + /** * @param min * @param max @@ -45,7 +46,7 @@ public static Integer createInteger(Integer min, Integer max) { */ public static Integer[] createIntegers(int min, int max, int length) { Integer[] integers = new Integer[length]; - for(int i=0; i { - public StringDuplicateDeleter(String[] intArray){ - super (intArray); + public StringDuplicateDeleter(String[] intArray) { + super(intArray); } @@ -18,7 +19,7 @@ public String[] removeDuplicatesExactly(int exactNumberOfDuplications) { String[] noStringDupsArray = new String[0]; - for (int i = 0; i < this.array.length; i++){ + for (int i = 0; i < this.array.length; i++) { if (getNumberOfOccurrences(this.array, this.array[i]) != exactNumberOfDuplications) { @@ -37,9 +38,9 @@ public static int getNumberOfOccurrences(String[] inputArray, String value) { int valueCounter = 0; - for (String arrayElement : inputArray){ + for (String arrayElement : inputArray) { - if (arrayElement.equalsIgnoreCase(value)){ + if (arrayElement.equalsIgnoreCase(value)) { valueCounter++; } @@ -54,12 +55,12 @@ public static int getNumberOfOccurrences(String[] inputArray, String value) { public String[] removeDuplicates(int maxNumberOfDuplications) { String[] maxDupsArray = new String[0]; - for (int i = 0; i < this.array.length; i++){ + for (int i = 0; i < this.array.length; i++) { - if (getNumberOfOccurrences(this.array, this.array[i]) < maxNumberOfDuplications){ + if (getNumberOfOccurrences(this.array, this.array[i]) < maxNumberOfDuplications) { int arrayElements = maxDupsArray.length; - maxDupsArray = Arrays.copyOf(maxDupsArray, maxDupsArray.length+1); + maxDupsArray = Arrays.copyOf(maxDupsArray, maxDupsArray.length + 1); maxDupsArray[arrayElements] = this.array[i]; } diff --git a/src/test/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleterTest.java b/src/test/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleterTest.java index 3388c27..d83ae3e 100644 --- a/src/test/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleterTest.java +++ b/src/test/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleterTest.java @@ -7,6 +7,7 @@ /** * Created by leon on 1/25/18. + * * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class. */ public class IntegerDuplicateDeleterTest { @@ -37,7 +38,6 @@ public void testRemoveDuplicatesExactly1() { } - @Test public void testRemoveDuplicatesExactly2() { Integer[] expected = new Integer[]{0, 0, 0, 2, 2, 4, 4, 5, 5, 5, 9, 9, 9}; @@ -58,31 +58,6 @@ public void testRemoveDuplicatesExactly3() { } - - - - - - - - - - - - - - - - - - - - - - - - - @Test public void testRemoveDuplicates0() { Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5}; @@ -117,7 +92,7 @@ public void testRemoveDuplicates2() { public void testRemoveDuplicates3() { Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5}; DuplicateDeleter deleter = new IntegerDuplicateDeleter(array); - Integer[] expected = new Integer[]{1,1,2,4,4}; + Integer[] expected = new Integer[]{1, 1, 2, 4, 4}; Integer[] actual = deleter.removeDuplicates(3); TestUtils.assertArrayEquality(expected, actual); } @@ -127,28 +102,15 @@ public void testRemoveDuplicates3() { public void testRemoveDuplicates4() { Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5}; DuplicateDeleter deleter = new IntegerDuplicateDeleter(array); - Integer[] expected = new Integer[]{0,0,0,1,1,2,3,3,3,4,4}; + Integer[] expected = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4}; Integer[] actual = deleter.removeDuplicates(4); TestUtils.assertArrayEquality(expected, actual); } - - - - - - - - - - - - - @Test public void testRemoveDuplicatesExactlyIdempotence() { - Integer[] input = RandomNumberFactory.createIntegers(0,50,150); + Integer[] input = RandomNumberFactory.createIntegers(0, 50, 150); DuplicateDeleter deleter = new IntegerDuplicateDeleter(input); Integer[] expected = deleter.removeDuplicatesExactly(5); @@ -166,7 +128,7 @@ public void testRemoveDuplicatesExactlyIdempotence() { @Test public void testRemoveDuplicatesIdempotence() { - Integer[] input = RandomNumberFactory.createIntegers(0,50,150); + Integer[] input = RandomNumberFactory.createIntegers(0, 50, 150); DuplicateDeleter deleter = new IntegerDuplicateDeleter(input); Integer[] expected = deleter.removeDuplicates(5); diff --git a/src/test/java/com/zipcodewilmington/looplabs/StringDuplicateDeleterTest.java b/src/test/java/com/zipcodewilmington/looplabs/StringDuplicateDeleterTest.java index e9225cf..8a75fe4 100644 --- a/src/test/java/com/zipcodewilmington/looplabs/StringDuplicateDeleterTest.java +++ b/src/test/java/com/zipcodewilmington/looplabs/StringDuplicateDeleterTest.java @@ -8,6 +8,7 @@ /** * Created by leon on 1/28/18. + * * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class. */ public class StringDuplicateDeleterTest { @@ -63,18 +64,6 @@ public void testRemoveDuplicatesExactly5() { } - - - - - - - - - - - - @Test public void testRemoveDuplicates0() { String[] input = new String[]{"aa", "aa", "aa", "aa", "aa", "ab", "ba", "ba", "ba", "ba", "bb", "bb", "bb", "bb", "bb"}; @@ -85,7 +74,6 @@ public void testRemoveDuplicates0() { } - @Test public void testRemoveDuplicates1() { String[] input = new String[]{"aa", "aa", "aa", "aa", "aa", "ab", "ba", "ba", "ba", "ba", "bb", "bb", "bb", "bb", "bb"}; @@ -115,24 +103,6 @@ public void testRemoveDuplicates3() { } - - - - - - - - - - - - - - - - - - @Test public void testRemoveDuplicatesExactlyIdempotence() { String[] input = RandomNumberFactory.createStrings('a', 'c', 2, 15); diff --git a/src/test/java/com/zipcodewilmington/looplabs/TestSuite.java b/src/test/java/com/zipcodewilmington/looplabs/TestSuite.java index b519741..8bc98f8 100644 --- a/src/test/java/com/zipcodewilmington/looplabs/TestSuite.java +++ b/src/test/java/com/zipcodewilmington/looplabs/TestSuite.java @@ -5,6 +5,7 @@ /** * Created by leon on 1/28/18. + * * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class. */ @RunWith(Suite.class) diff --git a/src/test/java/com/zipcodewilmington/looplabs/TestUtils.java b/src/test/java/com/zipcodewilmington/looplabs/TestUtils.java index 1c07809..14d952a 100644 --- a/src/test/java/com/zipcodewilmington/looplabs/TestUtils.java +++ b/src/test/java/com/zipcodewilmington/looplabs/TestUtils.java @@ -6,6 +6,7 @@ /** * Created by leon on 1/28/18. + * * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class. */ public class TestUtils {