Skip to content
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

Feedback #1

Open
wants to merge 16 commits into
base: feedback
Choose a base branch
from
Prev Previous commit
Next Next commit
Finished part 2, on to part 3
  • Loading branch information
Jon authored and Jon committed Jul 8, 2024
commit 05648cd51f215a496e168e193de2332dd3998a97
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.zipcodewilmington.assessment1.part2;

import static com.zipcodewilmington.assessment1.part1.BasicStringUtils.reverse;

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -11,7 +13,8 @@ public class StringUtils {
* given a string containing words delimited by spaces, representative of a sentence, return an array of strings, each element representative of a respective word in the sentence
*/
public static String[] getWords(String sentence) {
return null;

return sentence.split("\\s+");
}


Expand All @@ -21,7 +24,12 @@ public static String[] getWords(String sentence) {
* given a string containing words delimited by spaces, representative of a sentence, return the first word of the sentence
*/
public static String getFirstWord(String sentence) {
return null;
String[] wordsIn = sentence.split("\\s+");
if (wordsIn.length > 0) {
return wordsIn[0];
} else {
return null;
}
}

/**
Expand All @@ -30,27 +38,48 @@ public static String getFirstWord(String sentence) {
* given a string containing words delimited by spaces, representative of a sentence, return the first word with identical contents in reverse order
*/
public static String reverseFirstWord(String sentence) {
return null;
String[] wordsIn = sentence.split("\\s+");
if (wordsIn.length > 0) {
//Call to the first word with index 0
String firstWord = wordsIn[0];
} else {
return null;
}

//Create new string with string builder -- use index to return first word
StringBuilder reversedString = new StringBuilder(wordsIn[0]);
return reversedString.reverse().toString();
}


/**
* @param sentence a string containing words delimited by spaces, representative of a sentence
* @return the first word in the specified sentence, with identical contents in reverse order and the first character capitalized
* given a string containing words delimited by spaces, representative of a sentence, return the first word with identical contents in reverse order with the first character capitalized
*/
public static String reverseFirstWordThenCamelCase(String sentence) {
return null;
}
String[] wordsIn = sentence.split("\\s+");

//Isolate first word and then reverse
if (wordsIn.length > 0) {
String firstWord = wordsIn[0];
String reversed = reverse(firstWord);
//Capitalize first word
return reversed.substring(0, 1).toUpperCase() + reversed.substring(1);
} else {
return null;
}
}

/**
* @param str string input from client
* @param str string input from client
* @param index the index of the character to be removed from `str`
* @return string with identical contents, excluding the character at the specified index
* given a string and index, return an identical string excluding the character at the specified index
*/
public static String removeCharacterAtIndex(String str, int index) {
return null;

return str.substring(0, index) + str.substring(index + 1);
}

}