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>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ 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,35 @@ 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).toLowerCase();
}

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



return stringBuilder.reverse().toString();
}

/**
* @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;
StringBuilder stringBuilder = new StringBuilder(str);
stringBuilder.reverse();





return BasicStringUtils.camelCase(stringBuilder.toString());
}


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

StringBuilder stringBuilder = new StringBuilder(str);
int i = str.length() - 1;

stringBuilder.deleteCharAt(i);
stringBuilder.deleteCharAt(0);
return stringBuilder.toString();
}

/**
* @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[] chars = str.toCharArray();
for (int i = 0; i < chars.length; i++)
{
char c = chars[i];
if (Character.isUpperCase(c))
{
chars[i] = Character.toLowerCase(c);
}
else if (Character.isLowerCase(c))
{
chars[i] = Character.toUpperCase(c);
}
}
return new String(chars);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,43 @@ public class IntegerArrayUtils {
* @return the sum of `intArray`
*/
public static Integer getSum(Integer[] intArray) {
return null;
Integer sum = 0;

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


return sum;
}

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

Integer product = 1;

for(int i = 0; i < intArray.length; i++){
product *= intArray[i];
}


return product;
}

/**
* @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;
Double sum = 0.0;

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

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,48 @@ 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;

int i =1;

while (i <= n){
sum = sum + i;
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;

int i =1;

while (i <= n){
sum = sum * i;
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;

int toBeReversed = 0;

int remainder;

while (val > 0){
remainder = val % 10;
toBeReversed = (toBeReversed * 10) + remainder;
val = val / 10;
}
return toBeReversed;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.zipcodewilmington.assessment1.part1;

import java.awt.print.Paper;
import java.util.Objects;

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -13,23 +16,52 @@ public class RockPaperSissorsEvaluator {
* @return the respective winning move
*/
public String getWinningMove(String handSign) {
return null;

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

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

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

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

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


/**
* @param handSignOfPlayer1 a string representative of a hand sign of a player
* @param handSignOfPlayer2 a string representative of a hand sign of a challenger
* @return a string representative of the winning hand sign between the two players
*/
public String getWinner(String handSignOfPlayer1, String handSignOfPlayer2) {
return null;
RockPaperSissorsEvaluator rps = new RockPaperSissorsEvaluator();

if(handSignOfPlayer2.equals(ROCK)) {
handSignOfPlayer1 = PAPER;
} else if (handSignOfPlayer2.equals(PAPER)) {
handSignOfPlayer1 = SCISSOR;
}else if (handSignOfPlayer2.equals(SCISSOR)) {
handSignOfPlayer1 = ROCK;

}
return handSignOfPlayer1;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package com.zipcodewilmington.assessment1.part2;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.stream.Stream;

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -11,19 +18,29 @@ public class ArrayUtils {
* Given an array of objects, named `objectArray`, and an object `objectToCount`, return the number of times the `objectToCount` appears in the `objectArray`
*/
public static Integer getNumberOfOccurrences(Object[] objectArray, Object objectToCount) {
return null;
int counter = 0;

for (Object o : objectArray)
if (objectToCount == o)
counter++;

return counter;
}


/**
* @param objectArray an array of any type of Object
* @param objectToRemove a value to be removed from the `objectArray`
* @return an array with identical content excluding the specified `objectToRemove`
* Given an array of objects, name `objectArray`, and an object `objectToRemove`, return an array of objects with identical contents excluding `objectToRemove`
*/
public static Object[] removeValue(Object[] objectArray, Object objectToRemove) {
return null;


return null;
}


/**
* @param objectArray an array of any type of Object
* @return the most frequently occurring object in the array
Expand All @@ -50,6 +67,23 @@ public static Object getLeastCommon(Object[] objectArray) {
* given two arrays `objectArray` and `objectArrayToAdd`, return an array containing all elements in `objectArray` and `objectArrayToAdd`
*/
public static Object[] mergeArrays(Object[] objectArray, Object[] objectArrayToAdd) {

// int length = objectArray.length + objectArrayToAdd.length;
// Object[] mergedArray = new Object[length];
// int position = 0;
//
// for (Object element : objectArray) {
// mergedArray[position] = element;
// position++;
// }
//
// for (Object element : objectArrayToAdd) {
// mergedArray[position] = element;
// position++;
//
// }
// return mergedArray;
return null;
}
}

Loading