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
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,37 @@ public class BasicArrayUtils {
* @return the first element in the array
*/
public static String getFirstElement(String[] stringArray) {
return null;
return stringArray[0];
//return null;
}

/**
* @param stringArray an array of String objects
* @return the second element in the array
*/
public static String getSecondElement(String[] stringArray) {
return null;
int getSecondToLastPosition = stringArray.length - 2;
return stringArray[getSecondToLastPosition];
//return null;
}

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

/**
* @param stringArray an array of String objects
* @return the second to last element in the array
*/
public static String getSecondToLastElement(String[] stringArray) {
return null;
int getSecondToLastPosition = stringArray.length - 2;
return stringArray[getSecondToLastPosition];
//return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,27 @@ public class BasicStringUtils {
* @return string with identical content, and the first character capitalized
*/
public static String camelCase(String str) {
return null;
return Character.toUpperCase(str.charAt(0)) + 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;
return new StringBuilder(str).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;
String reversed = new StringBuilder(str).reverse().toString();
return camelCase(reversed);

}


Expand All @@ -34,14 +38,25 @@ 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[] 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,34 @@ public class IntegerArrayUtils {
* @return the sum of `intArray`
*/
public static Integer getSum(Integer[] intArray) {
return null;
int sum = 0;
for (Integer num : intArray) {
sum += num;
}
return sum;

}

/**
* @param intArray an array of integers
* @return the product of `intArray`
*/
public static Integer getProduct(Integer[] intArray) {
return null;
int product = 1;
for (Integer num : intArray) {
product *= num;
}
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;
int sum = getSum(intArray);
return (double) sum / intArray.length;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,39 @@ 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 += 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 product = 1;
for (int i = 1; i <= n; i++) {
product *= i;
}
return product;

}

/**
* @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 reversed = 0;
while (val != 0) {
int digit = val % 10;
reversed = reversed * 10 + digit;
val /= 10;
}
return reversed;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,31 @@ 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;
}else{
return null;
}
}

/**
* @param handSign a string representative of a hand sign
* @return the respective losing move
*/
public String getLosingMove(String handSign) {
return null;
if (handSign.equals(ROCK)) {
return SCISSOR;
} else if (handSign.equals(PAPER)) {
return ROCK;
} else if (handSign.equals(SCISSOR)) {
return PAPER;
} else {
return null;
}
}

/**
Expand All @@ -30,6 +46,13 @@ 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;
// Determine the winner based on the rules of rock-paper-scissors
if (handSignOfPlayer1.equals(handSignOfPlayer2)) {
return "draw";
} else if (handSignOfPlayer1.equals(getWinningMove(handSignOfPlayer2))) {
return ROCK;
} else {
return handSignOfPlayer2 + handSignOfPlayer1;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.zipcodewilmington.assessment1.part2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -11,7 +15,14 @@ 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(int i = 0; i<objectArray.length; i++){
if(objectArray[i].equals(objectToCount)){
counter++;
}
}
return counter;

}

/**
Expand All @@ -24,6 +35,7 @@ public static Object[] removeValue(Object[] objectArray, Object objectToRemove)
return null;
}


/**
* @param objectArray an array of any type of Object
* @return the most frequently occurring object in the array
Expand All @@ -34,6 +46,7 @@ public static Object getMostCommon(Object[] objectArray) {
}



/**
* @param objectArray an array of any type of Object
* @return the least frequently occurring object in the array
Expand All @@ -50,6 +63,8 @@ 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) {
return null;
Object[] result = Arrays.copyOf(objectArray, objectArray.length + objectArrayToAdd.length);
System.arraycopy(objectArrayToAdd, 0, result, objectArray.length, objectArrayToAdd.length);
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.zipcodewilmington.assessment1.part2;

import java.util.ArrayList;
import java.util.List;

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -9,8 +12,17 @@ public class MultiplesDeleter {
* @return all ints which are not divisible by 2
* given an array of integers, named `ints` return an identical array with evens removed
*/


public Integer[] deleteEvens(Integer[] ints) {
return null;
List<Integer> result = new ArrayList<>();
for (Integer num : ints) {
if (num % 2 != 0) {
result.add(num);
}
}
return result.toArray(new Integer[0]);

}

/**
Expand All @@ -19,7 +31,14 @@ public Integer[] deleteEvens(Integer[] ints) {
* given an array of integers, named `ints` return an identical array with odds removed
*/
public Integer[] deleteOdds(Integer[] ints) {
return null;
List<Integer> result = new ArrayList<>();
for (Integer num : ints) {
if (num % 2 == 0) {
result.add(num);
}
}
return result.toArray(new Integer[0]);

}

/**
Expand All @@ -28,7 +47,14 @@ public Integer[] deleteOdds(Integer[] ints) {
* given an array of integers, named `ints` return an identical array with numbers indivisible by 3 removed
*/
public Integer[] deleteMultiplesOf3(Integer[] ints) {
return null;
List<Integer> result = new ArrayList<>();
for (Integer num : ints) {
if (num % 3 != 0) {
result.add(num);
}
}
return result.toArray(new Integer[0]);

}

/**
Expand All @@ -38,6 +64,13 @@ public Integer[] deleteMultiplesOf3(Integer[] ints) {
* given an array of integers, named `ints` return an identical array with numbers indivisible by `multiple` removed
*/
public Integer[] deleteMultiplesOfN(Integer[] ints, int multiple) {
return null;
List<Integer> result = new ArrayList<>();
for (Integer num : ints) {
if (num % multiple != 0) {
result.add(num);
}
}
return result.toArray(new Integer[0]);
}

}
Loading