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,34 @@ 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;
return stringArray[1];
// return null;
}

/**
* @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];
// 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;
return stringArray[stringArray.length -2];
// return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.zipcodewilmington.assessment1.part1;

import com.zipcodewilmington.assessment1.part2.StringUtils;

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -9,23 +11,30 @@ public class BasicStringUtils {
* @return string with identical content, and the first character capitalized
*/
public static String camelCase(String str) {
return null;
String result = str.substring(0, 1).toUpperCase() + str.substring(1);
return result;
// return null;
}

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

/**
* @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 reverse = new StringBuilder(str).reverse().toString();
String result = reverse.substring(0, 1).toUpperCase() + reverse.substring(1);
return result;
// return null;
}


Expand All @@ -34,14 +43,35 @@ public static String reverseThenCamelCase(String str) {
* @return string with identical contents excluding first and last character
*/
public static String removeFirstAndLastCharacter(String str) {
return null;
String answer = str.substring(1, str.length()-1);
return answer;
// return null;
}

/**
* @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);

// int length = str.length();
//
// for (int i = 0; i < length; i++){
// Character c = str.charAt(i);
// if (Character.isLowerCase(c))
// str.replace(i, i + 1, Character.toUpperCase(c) + "");
// else
// }
// return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.zipcodewilmington.assessment1.part1;

import java.util.Arrays;
import java.util.stream.IntStream;

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -9,22 +12,35 @@ 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 + intArray[i];
return sum;
// return null;
}

/**
* @param intArray an array of integers
* @return the product of `intArray`
*/
public static Integer getProduct(Integer[] intArray) {
return null;
int product = 1;
for (int i : intArray)
product *= i;
return product;
// return null;
}

/**
* @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;
for (int num : intArray){
sum += num;
}
return (double) sum/intArray.length;
// return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,30 @@ 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 = n * (n + 1)/2;
return sum;
// return null;
}

/**
* @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 result = 1;
for (int i = 2; i <= n; i++)
result = result * i;
return result;
// return null;
}

/**
* @param val integer value input by client
* @return integer with identical digits in the reverse order
*/
public static Integer reverseDigits(Integer val) {
return null;
String reverse = new StringBuilder(String.valueOf(val)).reverse().toString();
return Integer.parseInt(reverse);
// return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,35 @@ public class RockPaperSissorsEvaluator {
* @return the respective winning move
*/
public String getWinningMove(String handSign) {
return null;
}
if (handSign == ROCK){
return PAPER;
}else if (handSign == PAPER){
return SCISSOR;
}else return ROCK;
}


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


/**
* @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;
}
}
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 numOfOcc = 0;
for (int i = 0; i < objectArray.length; i++) {
if (objectToCount == objectArray[i]) {
numOfOcc++;
}
}
return numOfOcc;
// return null;
}

/**
Expand All @@ -21,7 +32,12 @@ public static Integer getNumberOfOccurrences(Object[] objectArray, Object object
* 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;
int i, j;
for (i = j = 0; j < objectArray.length; j++)
if (!objectToRemove.equals(objectArray[j])) objectArray[i++] = objectArray[j];
objectArray = Arrays.copyOf(objectArray, i);
return objectArray;
// return null;
}

/**
Expand All @@ -30,7 +46,23 @@ public static Object[] removeValue(Object[] objectArray, Object objectToRemove)
* given an array of objects, named `objectArray` return the most frequently occuring object in the array
*/
public static Object getMostCommon(Object[] objectArray) {
return null;
int a = 1, tempCount;
Object common = objectArray[0];
int b = 0;
for (int i = 0; i < objectArray.length; i++) {
b = (int) objectArray[i];
tempCount = 0;
for (int j = 1; j < objectArray.length; j++) {
if (b == (int) objectArray[j])
tempCount++;
}
if (tempCount > a) {
common = b;
a = tempCount;
}
}
return common;
// return null;
}


Expand All @@ -40,6 +72,7 @@ public static Object getMostCommon(Object[] objectArray) {
* given an array of objects, named `objectArray` return the least frequently occuring object in the array
*/
public static Object getLeastCommon(Object[] objectArray) {

return null;
}

Expand All @@ -50,6 +83,17 @@ 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) {
Object[] newArray = new Object[objectArray.length + objectArrayToAdd.length];
int i = 0;

for (Object each : objectArray) {
newArray[i++] = each;
}
for (Object each : objectArrayToAdd) {
newArray[i++] = each;
}

return null;
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.zipcodewilmington.assessment1.part2;

import java.util.Arrays;

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -10,6 +12,7 @@ public class MultiplesDeleter {
* given an array of integers, named `ints` return an identical array with evens removed
*/
public Integer[] deleteEvens(Integer[] ints) {

return null;
}

Expand All @@ -19,7 +22,24 @@ public Integer[] deleteEvens(Integer[] ints) {
* given an array of integers, named `ints` return an identical array with odds removed
*/
public Integer[] deleteOdds(Integer[] ints) {
int countEven = 0;
int even[]= null;

for (int i : ints){
if (i % 2 == 0);
++countEven;
}

even = new int[countEven];

int i = 0;
for(int num : ints){
if (num % 2 == 0){
even[i++] = num;
}
}
return null;
// return null;
}

/**
Expand Down
Loading