Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #1

Open
wants to merge 3 commits into
base: feedback
Choose a base branch
from
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>11</source>
<target>11</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,29 @@ public class BasicStringUtils {
* @return string with identical content, and the first character capitalized
*/
public static String camelCase(String str) {
return null;
String camel = str.substring(0,1).toUpperCase() + str.substring(1);
return camel;
}

/**
* @param str string input from client
* @return string with identical contents, in the reverse order
*/
public static String reverse(String str) {
return null;
StringBuilder sb = new StringBuilder(str);
sb.reverse();
return sb.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 sb = new StringBuilder(str);
sb.reverse();
String camel = sb.substring(0,1).toUpperCase() + sb.substring(1);
return camel;
}


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[] 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,35 @@ 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 prod = 1;
for (int num : intArray){
prod *= num;
}
return prod;
}

/**
* @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;
}
double avg = sum / intArray.length;
return avg;
}
}
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 prod = 1;
for (int i = 1; i <= n; i++){
prod *= i;
}
return prod;
}

/**
* @param val integer value input by client
* @return integer with identical digits in the reverse order
*/
public static Integer reverseDigits(Integer val) {
return null;
StringBuilder sb = new StringBuilder(Integer.toString(val));
sb.reverse();
String num = sb.toString();
return Integer.valueOf(num);
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
package com.zipcodewilmington.assessment1.part1;

import java.util.HashMap;

/**
* Created by leon on 2/16/18.
*/
public class RockPaperSissorsEvaluator {
protected static final String ROCK = "rock";
protected static final String PAPER = "paper";
protected static final String SCISSOR = "scissor";
protected static final HashMap<String, String> losingMoves = new HashMap<>();
protected static final HashMap<String, String> winningMoves = new HashMap<>();

public RockPaperSissorsEvaluator() {
String[][] losingMovesArr = new String[][] {{ ROCK, SCISSOR }, { PAPER, ROCK }, { SCISSOR, PAPER }};
String[][] winningMovesArr = new String[][] { { ROCK, PAPER }, { PAPER, SCISSOR }, { SCISSOR, ROCK }};
for (int i = 0; i < losingMovesArr.length; i++) {
String[] losingMove = losingMovesArr[i];
String[] winningMove = winningMovesArr[i];
losingMoves.put(losingMove[0], losingMove[1]);
winningMoves.put(winningMove[0], winningMove[1]);
}
}


/**
* @param handSign a string representative of a hand sign
* @return the respective winning move
*/
public String getWinningMove(String handSign) {
return null;
return winningMoves.get(handSign);
}

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

/**
Expand All @@ -30,6 +46,10 @@ 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;

boolean didPlayer2Lose = losingMoves.get(handSignOfPlayer1).equals(handSignOfPlayer2);
boolean didPlayer1Lose = losingMoves.get(handSignOfPlayer2).equals(handSignOfPlayer1);

return didPlayer2Lose ? handSignOfPlayer1 : didPlayer1Lose ? handSignOfPlayer2 : "tie";
}
}
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 occu = 0;
for (Object obj : objectArray){
if(objectToCount == obj){
occu +=1;
}
}
return occu;
}

/**
Expand All @@ -21,7 +29,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;
ArrayList<Object> arrList = new ArrayList<Object>(Arrays.asList(objectArray));
arrList.removeAll(Collections.singleton(objectToRemove));
return arrList.toArray(Integer[]::new);
}

/**
Expand All @@ -30,7 +40,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 count = 1;
Object mostCom = objectArray[0];
Object temp;
for (int i = 0; i < (objectArray.length - 1); i++) {
temp = objectArray[i];
int tempCount = 0;
for (int j = 1; j < objectArray.length; j++) {
if (temp == objectArray[j]) {
tempCount++;
}
}
if (tempCount > count) {
mostCom = temp;
count = tempCount;
}
}
return mostCom;
}


Expand All @@ -40,7 +66,26 @@ 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<Integer, Integer> frequencies = new HashMap<>();
int[] intArr = new int[objectArray.length];

for (int i = 0; i < objectArray.length; i++) {
intArr[i] = (Integer) objectArray[i];
}
for (int num : intArr) {
frequencies.put(num, frequencies.getOrDefault(num, 0) + 1);
}
int occu = Integer.MAX_VALUE;
int leastOccuNum = intArr[0];
for (int num : frequencies.keySet()) {
int freq = frequencies.get(num);
if (freq < occu) {
occu = freq;
leastOccuNum = num;
}
}
return leastOccuNum;
}

/**
Expand All @@ -50,6 +95,13 @@ 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;
Collection<Object> result = new ArrayList<Object>(objectArray.length + objectArrayToAdd.length);
for (Object val : objectArray) {
result.add(val);
}
for (Object val : objectArrayToAdd) {
result.add(val);
}
return result.toArray(Integer[]::new);
}
}
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.stream.Collectors;

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -10,7 +13,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;
return Arrays.stream(ints).filter(num -> num % 2 != 0).toArray(Integer[]::new);
}

/**
Expand All @@ -19,7 +22,7 @@ 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;
return Arrays.stream(ints).filter(num -> num % 2 == 0).toArray(Integer[]::new);
}

/**
Expand All @@ -28,7 +31,7 @@ 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;
return Arrays.stream(ints).filter(num -> num % 3 != 0).toArray(Integer[]::new);
}

/**
Expand All @@ -38,6 +41,6 @@ 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;
return Arrays.stream(ints).filter(num -> num % multiple != 0).toArray(Integer[]::new);
}
}
Loading