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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.zipcodewilmington.assessment1</groupId>
<artifactId>question1</artifactId>
<artifactId>assessment1</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<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,29 @@ 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;
String string = str;
String reverse = new StringBuffer(string).reverse().toString();
new StringBuilder(str).reverse().toString();
return reverse;
}

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


Expand All @@ -34,14 +40,23 @@ 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);
}
}
return new String(characters);
}
}
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 (int 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 (int i : intArray) {
product *= 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;
for (int num : intArray) {
sum += num;
}
return sum / intArray.length;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,33 @@ 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 sum = 1;
for (int i = 1; i <= n; i++) {
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;
String number = Integer.toString(val);
StringBuilder reverseString = new StringBuilder(number).reverse();
int reverseNumber = Integer.parseInt(reverseString.toString());
return reverseNumber;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,43 @@ public class RockPaperSissorsEvaluator {
* @return the respective winning move
*/
public String getWinningMove(String handSign) {
return null;
String winningSign = "";

switch (handSign) {
case "rock":
winningSign = "paper";
break;
case "paper":
winningSign = "scissors";
break;
case "scissors":
winningSign = "rock";
break;
}

return winningSign;
}

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

switch (handSign) {
case "rock":
losingSign = "scissor";
break;
case "paper":
losingSign = "rock";
break;
case "scissors":
losingSign = "paper";
break;
}

return losingSign;
}

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

import java.util.*;

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -11,7 +13,13 @@ 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 @@ -30,7 +38,19 @@ 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;
Map<Object, Integer> countMap = new HashMap<>();
for (Object obj : objectArray) {
countMap.put(obj, countMap.getOrDefault(obj, 0) + 1);
}
java.lang.Object mCommonObject = null;
int maxCount = 0;
for (Map.Entry<Object, Integer> entry : countMap.entrySet()) {
if (entry.getValue() > maxCount) {
maxCount = entry.getValue();
mCommonObject = entry.getKey();
}
}
return (Object) mCommonObject;
}


Expand All @@ -40,7 +60,19 @@ 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;
Map<Object, Integer> countMap = new HashMap<>();
for (Object obj : objectArray) {
countMap.put(obj, countMap.getOrDefault(obj, 0) + 1);
}
Object lCommonObject = null;
int minCount = Integer.MAX_VALUE;
for (Map.Entry<Object, Integer> entry : countMap.entrySet()) {
if (entry.getValue() < minCount) {
minCount = entry.getValue();
lCommonObject = entry.getKey();
}
}
return (Object)lCommonObject;
}

/**
Expand All @@ -50,6 +82,11 @@ 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;
int length1 = objectArray.length;
int length2 = objectArrayToAdd.length;
int combinedLength = length1 + length2;
Object[] resultArray = Arrays.copyOf(objectArray, combinedLength);
System.arraycopy(objectArrayToAdd, 0, resultArray, length1, length2);
return resultArray;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.zipcodewilmington.assessment1.part2;

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

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -10,7 +13,20 @@ public class MultiplesDeleter {
* given an array of integers, named `ints` return an identical array with evens removed
*/
public Integer[] deleteEvens(Integer[] ints) {
return null;
int countOdds = 0;
for (int num : ints) {
if (num % 2 != 0) {
countOdds++;
}
}
Integer[] odds = new Integer[countOdds];
int index = 0;
for (int num : ints) {
if (num % 2 != 0) {
odds[index++] = num;
}
}
return odds;
}

/**
Expand All @@ -19,7 +35,20 @@ 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;
int countEvens = 0;
for (int num : ints) {
if (num % 2 == 0) {
countEvens++;
}
}
Integer[] evens = new Integer[countEvens];
int index = 0;
for (int num : ints) {
if (num % 2 == 0) {
evens[index++] = num;
}
}
return evens;
}

/**
Expand All @@ -28,7 +57,21 @@ 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;
int numDivisibleByThree = 0;
for (int num : ints) {
if (num % 3 == 0) {
numDivisibleByThree++;
}
}
Integer[] divisibleByThree = new Integer[numDivisibleByThree];
int index = 0;
for (int num : ints) {
if (num % 3 == 0) {
divisibleByThree[index++] = num+1;
}
}
return divisibleByThree;

}

/**
Expand All @@ -38,6 +81,20 @@ 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;
int numDivisibleByMultiple = 0;
for (int num : ints) {
if (num % multiple != 0) {
numDivisibleByMultiple++;
}
}
Integer[] divisibleByMultiple = new Integer[numDivisibleByMultiple];
int index = 0;
for (int num : ints) {
if (num % multiple != 0) {
divisibleByMultiple[index++] = num;
}
}
return divisibleByMultiple;

}
}
Loading