From 477400ba47e6f9f2051fddcec2879f024639f70e Mon Sep 17 00:00:00 2001 From: Daniel Horowitz Date: Fri, 9 Feb 2018 19:00:10 -0500 Subject: [PATCH 1/2] i am sorry for what you are about to witness Leon --- .../looplabs/IntegerDuplicateDeleter.java | 38 +++++++++++++++++++ .../looplabs/StringDuplicateDeleter.java | 17 +++++++++ 2 files changed, 55 insertions(+) diff --git a/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java b/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java index ee550c5..1677889 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java @@ -5,4 +5,42 @@ * @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) { + + //String without = " "; + + + return new Integer[0]; + } + + @Override + public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) { + + String without = ""; + int counter = 0; + + for (int x = 0; x < this.array.length; x ++) { + for(int y = 0; y < this.array.length; y++) { + if (this.array[x].equals(this.array[y])) { + counter++; + } + } + if (counter != exactNumberOfDuplications) { + without += this.array[x] + " "; + } + counter = 0; + } + String[] last = without.split(" "); + Integer[] done = new Integer[last.length]; + for (int i = 0; i < last.length; i++) { + done[i] = Integer.parseInt(last[i]); + } + System.out.println(done); + return done; + } } diff --git a/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java b/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java index 4818fe3..5e68e3b 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java @@ -5,4 +5,21 @@ * @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) { + + + return new String[0]; + } + + @Override + public String[] removeDuplicatesExactly(int exactNumberOfDuplications) { + + + return new String[0]; + } } From d2c309b39218ff67d9603e1420541b1f8528c72b Mon Sep 17 00:00:00 2001 From: Daniel Horowitz Date: Sat, 10 Feb 2018 11:04:05 -0500 Subject: [PATCH 2/2] complete and ugly --- .../looplabs/IntegerDuplicateDeleter.java | 32 ++++++++++++- .../looplabs/StringDuplicateDeleter.java | 45 ++++++++++++++++++- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java b/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java index 1677889..f11bef3 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java @@ -12,15 +12,43 @@ public IntegerDuplicateDeleter(Integer[] intArray) { @Override public Integer[] removeDuplicates(int maxNumberOfDuplications) { - //String without = " "; + String without = ""; + int counter = 0; + int times = 0; + + for (int x = 0; x < this.array.length; x++) { + for (int y = 0; y < this.array.length; y++) { + if (this.array[x].equals(this.array[y])) { + counter++; + } + } + if (counter < maxNumberOfDuplications) { + without += this.array[x] + " "; + times++; + } + counter = 0; + } + + if (times > 0) { + String[] last = without.split(" "); + Integer[] done = new Integer[last.length]; + for (int i = 0; i < last.length; i++) { + done[i] = Integer.parseInt(last[i]); + + } return done; + + } else { + Integer[] check = new Integer[0]; + return check; + } - return new Integer[0]; } @Override public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) { + String without = ""; int counter = 0; diff --git a/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java b/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java index 5e68e3b..e3d34c0 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java @@ -11,15 +11,56 @@ public StringDuplicateDeleter(String[] intArray) { @Override public String[] removeDuplicates(int maxNumberOfDuplications) { + String without = ""; + int counter = 0; + int times = 0; + + for (int x = 0; x < this.array.length; x ++) { + for(int y = 0; y < this.array.length; y++) { + if (this.array[x].equals(this.array[y])) { + counter++; + } + } + if (counter < maxNumberOfDuplications) { + without += this.array[x] + " "; + times++; + } + counter = 0; + } + String[] last = without.split(" "); + + if (times > 0) { + return last; + + } else { + String[] going = new String[0]; + return going; + } - return new String[0]; } + @Override public String[] removeDuplicatesExactly(int exactNumberOfDuplications) { + String without = ""; + int counter = 0; + + for (int x = 0; x < this.array.length; x ++) { + for(int y = 0; y < this.array.length; y++) { + if (this.array[x].equals(this.array[y])) { + counter++; + } + } + if (counter != exactNumberOfDuplications) { + without += this.array[x] + " "; + } + counter = 0; + } + String[] last = without.split(" "); - return new String[0]; + System.out.println(last); + return last; } }