Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public DuplicateDeleter(T[] intArray) {

abstract public T[] removeDuplicates(int maxNumberOfDuplications);
abstract public T[] removeDuplicatesExactly(int exactNumberOfDuplications);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
public interface DuplicateDeleterInterface<T> {
T[] removeDuplicates(int maxNumberOfDuplications);
T[] removeDuplicatesExactly(int exactNumberOfDuplications);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,77 @@
* @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
*/
public final class IntegerDuplicateDeleter extends DuplicateDeleter<Integer> {

public IntegerDuplicateDeleter(Integer[] intArray) {

super(intArray);
}

@Override
public Integer[] removeDuplicates(int maxCopies) {

StringBuilder goku = new StringBuilder();

for (Integer ssjGoku : array) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redo ALL the instance variable names; these are worse than meaningless.


int count = 0;

for (int i = 0; i < array.length; i++) {
Integer gokuLevel = array[i];
if (ssjGoku == gokuLevel)
count++;
}

if (count < maxCopies) {
goku.append(ssjGoku);
goku.append(" ");
}
}

String[] powerUp = goku.toString().split(" ");
if (goku.toString().isEmpty()){

return new Integer[0];
}

Integer[] ssjTwo = new Integer[powerUp.length];
for (int i = 0; i < powerUp.length; i++) {

if (!powerUp[i].isEmpty()) {
ssjTwo[i] = new Integer(powerUp[i]);
}
}

return ssjTwo;
}

@Override
public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) {

StringBuilder vegeta = new StringBuilder();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redo ALL the instance variable names; these are worse than meaningless.


for (Integer integer : array) {
int count = 0;

for (int i = 0; i < array.length; i++) {
Integer comp = array[i];
if (integer == comp)
count++;
}

if (count != exactNumberOfDuplications) {
vegeta.append(integer);
vegeta.append(" ");
}
}

String[] ssjVegeta = vegeta.toString().split(" ");
Integer[] superVegeta = new Integer[ssjVegeta.length];
for (int i = 0; i < ssjVegeta.length; i++) {
superVegeta[i] = new Integer(superVegeta[i]);
}

return superVegeta;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
*/
public final class RandomNumberFactory {
private static volatile Random random = new Random();

private RandomNumberFactory() {
private RandomNumberFactory() {
}
/**
* @param min
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,77 @@
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<String> {

public StringDuplicateDeleter(String[] intArray) {

super(intArray);
}

@Override

public String[] removeDuplicates(int maxDuplications) {

String theRealest = "";
int counter = 0;

for (int i = 0; i < this.array.length; i++) {
for (int j = 0; j < this.array.length; j++) {
if (this.array[i].equals(this.array[j])) {
counter++;
}
}

if (counter < maxDuplications) {
theRealest += this.array[i] + " ";
}

counter = 0;
}
if (theRealest.length() < 1){
String[] emptyString = new String[]{};
return emptyString;
}
String[] resultStringArray = theRealest.split(" ");
return resultStringArray;
}

@Override
public String[] removeDuplicatesExactly(int exactDuplications) {

String theRealest = "";
int counter = 0;

for (int i = 0; i < this.array.length; i++) {
for (int k = 0; k < this.array.length; k++) {

if (this.array[i].equals(this.array[k])) {
counter++;
}
}

if (counter != exactDuplications) {
theRealest += this.array[i] + " ";
}

counter = 0;
}

String[] resultStringArray = theRealest.split(" ");
// String[] resultIntArray = new String[resultStringArray.length];

// for (int m = 0; m < resultIntArray.length; m++) {
// resultIntArray[m] = Integer.parseInt(resultStringArray[m]);
// }

return resultStringArray;
}
}


// the basket..

Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,12 @@ public void testRemoveDuplicatesIdempotence() {
System.out.println("Input:\n\t" + Arrays.toString(input));
TestUtils.assertArrayEquality(expected, actual);
}

@Test
public void removeDuplicates() {
}

@Test
public void removeDuplicatesExactly() {
}
}