-
Objective
- Ensure
StringArrayUtilsTestpasses each test by completing the methods stubbed out in the classStringArrayUtilsString getFirstElement(String[] array)String getSecondElement(String[] array)String getLastElement(String[] array)String getSecondToLastElement(String[] array)boolean contains(String[] array, String value)String[] reverse(String[] array)boolean isPalindromic(String[] array)boolean isPangramic(String[] array)int getNumberOfOccurrences(String[] array, String value)String[] removeValue(String[] array, String value)String[] removeConsecutiveDuplicates(String[] array)String[] packConsecutiveDuplicates(String[] array)
- Ensure
-
Purpose
- To establish greater familiarity with loops and arrays.
- To demonstrate the implementation of a Utility class
- To fork the project, click the
Forkbutton located at the top right of the project.
- Navigate to your github profile to find the newly forked repository.
- Copy the URL of the project to the clipboard.
- Clone the repository from your account into the
~/devdirectory.- if you do not have a
~/devdirectory, make one by executing the following command:mkdir ~/dev
- navigate to the
~/devdirectory by executing the following command:cd ~/dev
- clone the project by executing the following command:
git clone https://github.com/MYUSERNAME/NAMEOFPROJECT
- if you do not have a
- Ensure that the tests run upon opening the project.
- You should see
Tests Failed: 99 of 99 tests
- You should see
- from a terminal navigate to the root directory of the cloned project.
- from the root directory of the project, execute the following commands:
- add all changes
git add .
- commit changes to be pushed
git commit -m 'I have added changes'
- push changes to your repository
git push -u origin master
- add all changes
- from the browser, navigate to the forked project from your github account.
- click the
Pull Requeststab. - select
New Pull Request
- Description
- Given an array of
Stringobjects, return the first element of the array.
- Given an array of
- Sample Script
// : Given
String[] array = {"quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
// : When
String outcome = StringArrayUtils.getFirstElement(array);
// : Then
System.out.println(outcome);
- Sample Output
quick
- Sample Script
// : Given
String[] array = {"brown", "fox", "jumps", "over", "the", "lazy", "dog"};
// : When
String outcome = StringArrayUtils.getFirstElement(array);
// : Then
System.out.println(outcome);
- Sample Output
brown
- Sample Script
// : Given
String[] array = {"fox", "jumps", "over", "the", "lazy", "dog"};
// : When
String outcome = StringArrayUtils.getFirstElement(array);
// : Then
System.out.println(outcome);
- Sample Output
fox
- Description
- Given an array of
Stringobjects, return the first element of the array.
- Given an array of
- Sample Script
// : Given
String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
// : When
String outcome = StringArrayUtils.getSecondElement(array);
// : Then
System.out.println(outcome);
- Sample Output
quick
- Sample Script
// : Given
String[] array = {"quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
// : When
String outcome = StringArrayUtils.getFirstElement(array);
// : Then
System.out.println(outcome);
- Sample Output
brown
- Sample Script
// : Given
String[] array = {"brown", "fox", "jumps", "over", "the", "lazy", "dog"};
// : When
String outcome = StringArrayUtils.getFirstElement(array);
// : Then
System.out.println(outcome);
- Sample Output
fox
- Description
- Given an array of
Stringobjects, return the last element of the array.
- Given an array of
- Sample Script
// : Given
String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
// : When
String outcome = StringArrayUtils.getLastElement(array);
// : Then
System.out.println(outcome);
- Sample Output
dog
- Sample Script
// : Given
String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy"};
// : When
String outcome = StringArrayUtils.getLastElement(array);
// : Then
System.out.println(outcome);
- Sample Output
lazy
- Sample Script
// : Given
String[] array = {"the", "quick", "brown", "fox", "jumps", "over"};
// : When
String outcome = StringArrayUtils.getLastElement(array);
// : Then
System.out.println(outcome);
- Sample Output
the
- Description
- Given an array of
Stringobjects, return the next-to-last element of the array.
- Given an array of
- Sample Script
// : Given
String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
// : When
String outcome = StringArrayUtils.getSecondToLastElement(array);
// : Then
System.out.println(outcome);
- Sample Output
lazy
- Sample Script
// : Given
String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "lazy"};
// : When
boolean outcome = StringArrayUtils.getNextToLastElement(array);
// : Then
System.out.println(outcome);
- Sample Output
over
- Sample Script
// : Given
String[] array = {"the", "quick", "brown", "fox", "jumps", "over"};
// : When
boolean outcome = StringArrayUtils.getNextToLastElement(array);
// : Then
System.out.println(outcome);
- Sample Output
jumps
- Description
- Given an array of
Stringobjects namedarrayand aStringobject namedvalue
return true ifvalueappears inarrays.
- Given an array of
- Sample Script
// : Given
String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
// : When
boolean outcome = StringArrayUtils.contains(array, "the");
// : Then
System.out.println(outcome);
- Sample Output
true
- Sample Script
// : Given
String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
// : When
boolean outcome = StringArrayUtils.contains(array, "potatoes");
// : Then
System.out.println(outcome);
- Sample Output
false
- Description
- Given an array of
Stringobjects, return an array with identical contents in reverse order.
- Given an array of
- Sample Script
// : Given
String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
// : When
boolean outcome = StringArrayUtils.contains(array, "the");
// : Then
System.out.println(outcome);
- Sample Output
[dog, lazy, the, over, jumps, fox, brown, quick, the]
- Sample Script
// : Given
String[] array = {"Pack", "my", "box", "with", "five", "dozen", "liquor", "jugs"};
// : When
boolean outcome = StringArrayUtils.contains(array, "potatoes");
// : Then
System.out.println(outcome);
- Sample Output
[jugs, liquor, dozen, five, with, box, my, Pack]
- Sample Script
// : Given
String[] array = {"The", "quick", "onyx", "goblin", "jumps", "over", "the", "lazy", "dwarf"};
// : When
boolean outcome = StringArrayUtils.contains(array, "potatoes");
// : Then
System.out.println(outcome);
- Sample Output
[dwarf, lazy, the, over, jumps, goblin, onyx, quick, The]
- Description
- A palindrome is a sequence that is the same backwards and forwards.
- Given an array of
Stringobjects, returntrueif the array is palindromic.
- Sample Script
// : Given
String[] array = {"a", "b", "c", "b", "a"}
// : When
boolean outcome = StringArrayUtils.isPalindrome(array);
// : Then
System.out.println(outcome);
- Sample Output
true
- Sample Script
// : Given
String[] array = {"Is this a plaindrome?", "This is a plaindrome", "Is this a palindrome?"}
// : When
boolean outcome = StringArrayUtils.isPalindrome(array);
// : Then
System.out.println(outcome);
- Sample Output
true
- Sample Script
// : Given
String[] array = {"Is this a plaindrome?", "This is not a plaindrome", "Is this a palindrome?", "This is not a palindrome"}
// : When
boolean outcome = StringArrayUtils.isPalindrome(array);
// : Then
System.out.println(outcome);
- Sample Output
false
- Description
- A pangram is a sequence that contains all letters of the alphabet.
- Given an array of
Stringobjects, returntrueif the array is palindromic.
- Sample Script
// : Given
String[] array = {"The quick brown", "Fox jumps over", "The lazy dog"}
// : When
boolean outcome = StringArrayUtils.isPangramic(array);
// : Then
System.out.println(outcome);
- Sample Output
true
- Sample Script
// : Given
String[] array = {"The", "quick", "onyx", "goblin", "jumps", "over", "the", "lazy", "dwarf"};
// : When
boolean outcome = StringArrayUtils.isPangramic(array);
// : Then
System.out.println(outcome);
- Sample Output
true
- Description
- Given an array of
Stringobjects namedarrayand aStringobject namedvalue
return the number of timesvalueappears inarrays
- Given an array of
- Sample Script
// : Given
String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
// : When
int numberOfOccurrences = StringArrayUtils.getNumberOfOccurrences(array, "bba");
// : Then
System.out.println(numberOfOccurrences);
- Sample Output
4
- Sample Script
// : Given
String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
// : When
int numberOfOccurrences = StringArrayUtils.getNumberOfOccurrences(array, "bbb");
// : Then
System.out.println(numberOfOccurrences);
- Sample Output
2
- Sample Script
// : Given
String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
// : When
int numberOfOccurrences = StringArrayUtils.getNumberOfOccurrences(array, "baa");
// : Then
System.out.println(numberOfOccurrences);
- Sample Output
1
- Description
- Given an array of
Stringobjects, return an array of Strings with conseuctive duplicates removed.
- Given an array of
- Sample Script
// : Given
String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
// : When
String[] actual = StringArrayUtils.removeConsecutiveDuplicates(array);
// : Then
System.out.println(Arrays.toString(actual));
- Sample Output
[aba, baa, bab, bba, bbb];
- Sample Script
// : Given
String[] array = {"aba", "aba", "baa", "bab", "bba", "zzz", "bba", "bba", "bba", "bbb", "bbb"};
// : When
String[] actual = StringArrayUtils.removeConsecutiveDuplicates(array);
// : Then
System.out.println(Arrays.toString(actual));
- Sample Output
[aba, baa, bab, bba, zzz, bba, bbb];
- Sample Script
// : Given
String[] array = {"aba", "aba", "baa", "bab", "bba", "zzz", "bba", "bba", "bba", "bbb", "bbb", "aba", "bbb"};
// : When
String[] actual = StringArrayUtils.removeConsecutiveDuplicates(array);
// : Then
System.out.println(Arrays.toString(actual));
- Sample Output
[aba, baa, bab, bba, zzz, bba, aba, bbb];
- Description
- Given an array of
charobjects, return an array of Strings with consecutive duplicates placed in an array.
- Given an array of
- Sample Script
// : Given
String[] array = {"a", "a", "a", "a", "b", "c", "c", "a", "a", "d"};
// : When
String[] actual = StringArrayUtils.packConsecutiveDuplicates(array);
// : Then
System.out.println(Arrays.toString(actual));
- Sample Output
[aaa, b, cc, aa, d, eee];
- Sample Script
// : Given
String[] array = {"t", "t", "q", "a", "a", "a", "b", "c", "c", "a", "a", "d", "e", "e", "e"};
// : When
String[] actual = StringArrayUtils.packConsecutiveDuplicates(array);
// : Then
System.out.println(Arrays.toString(actual));
- Sample Output
[tt, q, aaa, b, cc, aa, d, eee];
- Sample Script
// : Given
String[] array = {"m", "o", "o", "n", "m", "a", "n"}
// : When
String[] actual = StringArrayUtils.packConsecutiveDuplicates(array);
// : Then
System.out.println(Arrays.toString(actual));
- Sample Output
[m, oo, n, m, a, n];
- Description
- Given an array of
Stringobjects namedarrayand aStringobject namedvalueToRemove
create and return an array containing identical contents excluding objects whose value is equivalent tovalueToRemove. Ensure that the length of the newly created array has been resized based on the removal of the undesired elements.
- Given an array of
-
Sample Script
// : Given String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"}; // : When String[] actual = StringArrayUtils.removeValues(array, "aba"); // : Then System.out.println(Arrays.toString(actual)); -
Sample Output
[baa, bab, bba, bba, bba, bba, bbb, bbb};
-
Sample Script
// : Given String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"}; // : When String[] actual = StringArrayUtils.removeValues(array, "bba"); // : Then System.out.println(Arrays.toString(actual)); -
Sample Output
[aba, aba, baa, bab, bbb, bbb];
-
Sample Script
// : Given String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"}; // : When String[] actual = StringArrayUtils.removeValues(array, "bbb"); // : Then System.out.println(Arrays.toString(actual)); -
Sample Output
[aba, aba, baa, bab, bba, bba, bba, bba];