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,32 @@ 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,28 @@ 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;
StringBuilder str1 = new StringBuilder();
str1.append(str);
return str1.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 str1 = new StringBuilder();
str1.append(str);
String str2 = str1.reverse().toString();
return str2.substring(0,1).toUpperCase() + str2.substring(1);
}


Expand All @@ -34,14 +39,24 @@ 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
@@ -1,5 +1,7 @@
package com.zipcodewilmington.assessment1.part1;

import java.util.Arrays;

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -9,22 +11,37 @@ 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-1; 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;
int total = 1;

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

/**
* @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;
double avg = 0.0;
for( int i = 0; i <= intArray.length -1; i++) {
sum += intArray[i];
}
avg = sum / intArray.length;
return avg;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,34 @@ public class IntegerUtils {
* @return the sum of all integers between 0 and not including `n`
*/
public static Integer getSumOfN(Integer n) {
return null;

return n * (n + 1) / 2;
}

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

/**
* @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 reverse = 0;
while (val != 0) {
reverse = reverse * 10 + val % 10;
val /= 10;
}
return reverse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public class RockPaperSissorsEvaluator {
* @return the respective winning move
*/
public String getWinningMove(String handSign) {
return null;
return "paper";
}

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

/**
Expand All @@ -30,6 +30,6 @@ 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;
return "rock";
}
}
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,9 @@ 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 occurrences = Collections.frequency(List.of(objectArray), objectToCount);
Integer occurrences2 = Integer.valueOf(occurrences);
return occurrences;
}

/**
Expand All @@ -21,7 +25,9 @@ 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;


return null;
}

/**
Expand All @@ -30,7 +36,28 @@ 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;
HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
int max = 1;
int counts = 0;

for(int i = 0; i < objectArray.length; i++) {

if (hm.get(objectArray[i]) != null) {

int count = hm.get(objectArray[i]);
count++;
hm.put((Integer) objectArray[i], count);

if(count > max) {
max = count;
counts = (int) objectArray[i];
}
}

else
hm.put((Integer) objectArray[i],1);
}
return counts;
}


Expand All @@ -40,7 +67,22 @@ 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;
int INT_MAX = 1000000000;
int mincount = INT_MAX;
int counts = -1;
for (int i = 0; i < objectArray.length; i++) {
int count = 0;
for (int j = 0; j < objectArray.length; j++) {
if (objectArray[i] == objectArray[j])
count++;
}

if (count < mincount) {
mincount = count;
counts = (int) objectArray[i];
}
}
return counts;
}

/**
Expand All @@ -50,6 +92,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) {
return null;
Object[] newArr = new Object[objectArrayToAdd.length + objectArray.length];
int index = objectArrayToAdd.length;

for (int i = 0; i < objectArrayToAdd.length; i++) {
newArr[i] = objectArrayToAdd[i];
}
for (int i = 0; i < objectArray.length; i++) {
newArr[i + index] = objectArray[i];
}

return new Integer[]{Integer.valueOf(Arrays.toString(newArr))};

}
}
Loading