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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,33 @@ public class BasicArrayUtils {
* @return the first element in the array
*/
public static String getFirstElement(String[] stringArray) {
return null;

return stringArray[0];
}

/**
* @param stringArray an array of String objects
* @return the second element in the array
*/
public static String getSecondElement(String[] stringArray) {
return null;

return stringArray[1];
}

/**
* @param stringArray an array of String objects
* @return the last element in the array
*/
public static String getLastElement(String[] stringArray) {
return null;
return stringArray[stringArray.length-1];
}

/**
* @param stringArray an array of String objects
* @return the second to last element in the array
*/
public static String getSecondToLastElement(String[] stringArray) {
return null;

return stringArray[stringArray.length-2];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,32 @@ public class BasicStringUtils {
* @return string with identical content, and the first character capitalized
*/
public static String camelCase(String str) {
return null;

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

/**
* @param str string input from client
* @return string with identical contents, in the reverse order
*/
public static String reverse(String str) {
return null;
String reversedStr = "";

for (int i = 0; i < str.length(); i++) {
reversedStr = str.charAt(i) + reversedStr;
}

return reversedStr;
}

/**
* @param str string input from client
* @return string with identical contents, in reverse order, with first character capitalized
*/
public static String reverseThenCamelCase(String str) {
return null;


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


Expand All @@ -34,14 +43,38 @@ public static String reverseThenCamelCase(String str) {
* @return string with identical contents excluding first and last character
*/
public static String removeFirstAndLastCharacter(String str) {
return null;


return str.substring(1, str.length() - 1);
}

/**
* @param str a string input from user
* @return string with identical characters, each with opposite casing
*/
public static String invertCasing(String str) {
return null;

char[] characters = str.toCharArray();

for (int i =0; i < characters.length; i++){
char c = characters[i];
if(Character.isUpperCase(c)){
characters[i] = Character.toLowerCase(c);
} else if (Character.isLowerCase(c)) {
characters[i] = Character.toUpperCase(c);
}
}
// StringBuilder string = new StringBuilder();
//
// for (char c : str.toCharArray()) {
// if (Character.isUpperCase(c))
// c = Character.toLowerCase(c);
//
// else c = Character.toUpperCase(c);
// string.append(c);
// }


return new String(characters);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,47 @@ public class IntegerArrayUtils {
* @return the sum of `intArray`
*/
public static Integer getSum(Integer[] intArray) {
return null;
int sum = 0;

for(int i = 0; i <= intArray.length; i++){
sum = sum + i;
}


return sum;
}

/**
* @param intArray an array of integers
* @return the product of `intArray`
*/
public static Integer getProduct(Integer[] intArray) {
return null;

int sum = 1;

for(int i : intArray){
sum = sum * i;
}


return sum;


}

/**
* @param intArray an array of integers
* @return the sum of `intArray` divided by number of elements in `intArray`
*/
public static Double getAverage(Integer[] intArray) {
return null;
int sum = 0;
double avg = 0;
for (int i = 0; i <= intArray.length; i++) {
sum = sum + i;
avg = sum/intArray.length;
}


return avg;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,46 @@ public class IntegerUtils {
* @return the sum of all integers between 0 and not including `n`
*/
public static Integer getSumOfN(Integer n) {
return null;
int sum = 0;


for (int i = 0; i <= n; i++) {
sum = sum + i;
}
return sum;
}

/**
* @param n integer value input by client
* @return the product of all integers between 0 and not including `n`
*/
public static Integer getProductOfN(Integer n) {
return null;
int sum = 1;

for (int i = 1; i <= n; i++){
sum = sum * i;}



return sum;
}

/**
* @param val integer value input by client
* @return integer with identical digits in the reverse order
*/
public static Integer reverseDigits(Integer val) {
return null;
public static Integer reverseDigits(Integer val) {
int reverse = val;
StringBuilder sb = new StringBuilder();
sb.append(reverse);
sb = sb.reverse();
String string = sb.toString();

reverse = Integer.parseInt(string);

return reverse;


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,36 @@ public class RockPaperSissorsEvaluator {
* @return the respective winning move
*/
public String getWinningMove(String handSign) {
return null;
String winningMove = "";
if(handSign.equals(ROCK)){
return PAPER;
} else if (handSign.equals(PAPER)) {
return SCISSOR;
} else if (handSign.equals(SCISSOR)) {
return ROCK;

}

return winningMove;
}

/**
* @param handSign a string representative of a hand sign
* @return the respective losing move
*/
public String getLosingMove(String handSign) {
return null;
String losingMove = "";

if(handSign.equals(ROCK)){
return SCISSOR;
} else if (handSign.equals(PAPER)) {
return ROCK;
} else if (handSign.equals(SCISSOR)) {
return PAPER;

}

return losingMove;
}

/**
Expand All @@ -30,6 +51,12 @@ public String getLosingMove(String handSign) {
* @return a string representative of the winning hand sign between the two players
*/
public String getWinner(String handSignOfPlayer1, String handSignOfPlayer2) {
return null;
String winner = "";

if(handSignOfPlayer1.equals(ROCK) && handSignOfPlayer2.equals(SCISSOR)){
return ROCK;
}

return winner;
}
}
Loading