-
Notifications
You must be signed in to change notification settings - Fork 24
Done #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kmwd306
wants to merge
4
commits into
ZipCodeCore:master
Choose a base branch
from
kmwd306:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Done #30
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
99 changes: 98 additions & 1 deletion
99
src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,105 @@ | ||
| 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<Integer> { | ||
| } | ||
| //constructor | ||
| public IntegerDuplicateDeleter(Integer[] intArray) { | ||
| super(intArray); | ||
| } | ||
|
|
||
| Integer[] anIntArray = Arrays.copyOf(this.array, this.array.length); | ||
|
|
||
| @Override | ||
| public Integer[] removeDuplicates(int maxNumberOfDuplications) { | ||
|
|
||
| int noDuplicates = 0; | ||
| Integer[] duplicates = new Integer[0]; | ||
| int duplicatesIndex = 0; | ||
| for (int i = 0; i < anIntArray.length; i++) { | ||
| if (contains(duplicates, anIntArray[i])) { | ||
| continue; | ||
| } else if (getNumberOfOccurrences(anIntArray, anIntArray[i]) >= maxNumberOfDuplications) { | ||
| duplicates = Arrays.copyOf(duplicates, duplicates.length + 1); | ||
| duplicates[duplicatesIndex] = array[i]; | ||
| duplicatesIndex++; | ||
| } | ||
| } | ||
| Integer[] checking = Arrays.copyOf(anIntArray, anIntArray.length); | ||
| for (Integer k : duplicates) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just name
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will update! Thanks for the feedback! |
||
| checking = removeValue(checking, k); | ||
|
|
||
| } | ||
| return checking; | ||
| } | ||
|
|
||
|
|
||
| public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) { | ||
|
|
||
| int noDuplicates = 0; | ||
| Integer[] duplicates = new Integer[0]; | ||
| int duplicatesIndex = 0; | ||
| for (int i = 0; i < anIntArray.length; i++) { | ||
| if (contains(duplicates, anIntArray[i])) { | ||
| continue; | ||
| } else if (getNumberOfOccurrences(anIntArray, anIntArray[i]) == exactNumberOfDuplications) { | ||
| duplicates = Arrays.copyOf(duplicates, duplicates.length + 1); | ||
| duplicates[duplicatesIndex] = array[i]; | ||
| duplicatesIndex++; | ||
| } | ||
| } | ||
| Integer[] checking = Arrays.copyOf(anIntArray, anIntArray.length); | ||
| for (Integer k : duplicates) { | ||
| checking = removeValue(checking, k); | ||
|
|
||
| } | ||
| return checking; | ||
| } | ||
|
|
||
|
|
||
| public static int getNumberOfOccurrences(Integer[] array, Integer value) { | ||
|
|
||
| //created a countOccurence holder, to hold value everytime it appears | ||
|
|
||
| int countOccurence = 0; | ||
|
|
||
| for (Integer myValue : array) { | ||
| if (myValue.equals(value)) | ||
| countOccurence++; | ||
| } | ||
|
|
||
| return countOccurence; | ||
| } | ||
|
|
||
|
|
||
| public static Integer[] removeValue(Integer[] array, Integer valueToRemove) { | ||
|
|
||
| int newSize = array.length - getNumberOfOccurrences(array, valueToRemove); | ||
| Integer[] outputArray = new Integer[newSize]; | ||
| int indexNotDuplicates = 0; | ||
|
|
||
| for (int i = 0; i < array.length; i++) { | ||
| if (!array[i].equals(valueToRemove)) { | ||
| outputArray[indexNotDuplicates] = array[i]; | ||
| indexNotDuplicates++; | ||
| } | ||
| } | ||
| return outputArray; | ||
| } | ||
|
|
||
| public static boolean contains(Integer[] array, Integer value) { | ||
| /*the enhanced for loop starts at String myValue and searches to the end of array(so at every index comparing | ||
| . Then we add an if statement to see if the beginning of myValue equals value (which is what we are looking | ||
| for). */ | ||
| for (Integer myValue : array) { | ||
| if (myValue.equals(value)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
146 changes: 146 additions & 0 deletions
146
src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,154 @@ | ||
| 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> { | ||
|
|
||
|
|
||
| //constructor | ||
| public StringDuplicateDeleter (String[] intArray){ | ||
| super(intArray); | ||
|
|
||
| } | ||
| String[] anIntArray = Arrays.copyOf(this.array,this.array.length); | ||
|
|
||
|
|
||
| public String[] removeDuplicates(int maxNumberOfDuplications) { | ||
| //create copy of array, this will be your new array | ||
| //read array | ||
| //getNumberOfOccurences | ||
| //if getNumberOfOccurences appears more than once | ||
| //removeValue | ||
| //else | ||
| //store in newArray | ||
| //return values | ||
|
|
||
| /*private static final NULL_ARRAY = new String[0]; | ||
| else if (anIntArray == null){ | ||
| return NULL_ARRAY; | ||
| }*/ | ||
| /*okay first we are making a new array, but a copy, it will copy this.array which is intArray and copy | ||
| its length (it takes two parameters)*/ | ||
|
|
||
| int noDuplicates = 0; | ||
| String[] duplicates = new String[0]; | ||
| int duplicatesIndex = 0; | ||
| for (int i = 0; i < anIntArray.length; i++) { | ||
| if (contains(duplicates, anIntArray[i])) { | ||
| continue; | ||
| } else if (getNumberOfOccurrences(anIntArray, anIntArray[i]) >= maxNumberOfDuplications) { | ||
| duplicates = Arrays.copyOf(duplicates, duplicates.length + 1); | ||
| duplicates[duplicatesIndex] = array[i]; | ||
| duplicatesIndex++; | ||
| } | ||
| } | ||
| String[] checking = Arrays.copyOf(anIntArray, anIntArray.length); | ||
| for (String k : duplicates) { | ||
| checking = removeValue(checking, k); | ||
|
|
||
| } | ||
| return checking; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| public String[] removeDuplicatesExactly(int exactNumberOfDuplications){ | ||
|
|
||
| //create copy of array, this will be your new array | ||
| //read array | ||
| //getNumberOfOccurences | ||
| //if getNumberOfOccurences appears more than once | ||
| //removeValue | ||
| //else | ||
| //store in newArray | ||
| //return values | ||
|
|
||
| /*private static final NULL_ARRAY = new String[0]; | ||
| else if (anIntArray == null){ | ||
| return NULL_ARRAY; | ||
| }*/ | ||
| /*okay first we are making a new array, but a copy, it will copy this.array which is intArray and copy | ||
| its length (it takes two parameters)*/ | ||
|
|
||
| int noDuplicates = 0; | ||
| String[] duplicates = new String[0]; | ||
| int duplicatesIndex = 0; | ||
| for (int i = 0; i < anIntArray.length; i++) { | ||
| if (contains(duplicates, anIntArray[i])) { | ||
| continue; | ||
| } else if (getNumberOfOccurrences(anIntArray, anIntArray[i]) == exactNumberOfDuplications) { | ||
| duplicates = Arrays.copyOf(duplicates, duplicates.length + 1); | ||
| duplicates[duplicatesIndex] = array[i]; | ||
| duplicatesIndex++; | ||
| } | ||
| } | ||
| String[] checking = Arrays.copyOf(anIntArray, anIntArray.length); | ||
| for (String k : duplicates) { | ||
| checking = removeValue(checking, k); | ||
|
|
||
| } | ||
| return checking; | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| public static int getNumberOfOccurrences(String[] array, String value) { | ||
|
|
||
| //created a countOccurence holder, to hold value everytime it appears | ||
|
|
||
| int countOccurence = 0; | ||
|
|
||
| for (String myValue : array) { | ||
| if(myValue.equals(value)) | ||
| countOccurence++; | ||
| } | ||
|
|
||
| return countOccurence; | ||
| } | ||
|
|
||
|
|
||
| public static String[] removeValue(String[] array, String valueToRemove) { | ||
| /*1.we create this 'newSize' to hold the size of the array | ||
| 2.now we have to create the array, with the new array size. | ||
| 3.created a placeholder for things that were not duplicates | ||
| 4.looping through the array | ||
| 5. if the array indexes are not equal to valueToRemove | ||
| 6. the next line basically swaps the array i for the other & we add to the counter | ||
| 7. printing the new results */ | ||
| int newSize = array.length - getNumberOfOccurrences(array, valueToRemove); | ||
| String[] outputArray = new String[newSize]; | ||
| int indexNotDuplicates = 0; | ||
|
|
||
| for (int i =0; i <array.length; i++){ | ||
| if(!array[i].equalsIgnoreCase(valueToRemove)){ | ||
| outputArray[indexNotDuplicates] = array[i]; | ||
| indexNotDuplicates++; | ||
| } | ||
| } | ||
| return outputArray; | ||
| } | ||
|
|
||
| public static boolean contains(String[] array, String value) { | ||
| /*the enhanced for loop starts at String myValue and searches to the end of array(so at every index comparing | ||
| . Then we add an if statement to see if the beginning of myValue equals value (which is what we are looking | ||
| for). */ | ||
| for (String myValue : array) { | ||
| if(myValue.equals(value)){ | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this variable name is weird. If you're just using it to check if there is or isn't a duplicate, this should be a boolean. If you are checking for the number of duplicates, then it should be called numberOfDuplicates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will definitely update this, thank you for the feedback. I've already put this file on my computer again. I want to go through all of the labs again, maybe time myself...highlight the areas I don't know.