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];
}

/**
* @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,26 @@ 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 s = new StringBuilder();
return s.append(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;
return camelCase(reverse(str));

}


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

/**
* @param intArray an array of integers
* @return the product of `intArray`
*/
public static Integer getProduct(Integer[] intArray) {
return null;

Integer results =1;
for(Integer ele: intArray){
results *= ele;
}
return results;
}

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


return (double) (getSum(intArray) / intArray.length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,35 @@ public class IntegerUtils {
* @return the sum of all integers between 0 and not including `n`
*/
public static Integer getSumOfN(Integer n) {
return null;
Integer results =0;
for(int i =0; i<= n; i++){
results += i;
}

return results;
}

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

Integer results =1;
for(int i =1; i<= n; i++){
results *= i;
}

return results;
}

/**
* @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 s = new StringBuilder();
String numReversed = s.append(val.toString()).reverse().toString();
return Integer.parseInt(numReversed);
}
}
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 results = "";

switch(handSign){
case ROCK:
results = PAPER;
break;
case PAPER:
results = SCISSOR;
break;
case SCISSOR:
results = ROCK;
break;
}

return results;
}

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

switch(handSign){
case ROCK:
results = SCISSOR;
break;
case PAPER:
results = ROCK;
break;
case SCISSOR:
results = PAPER;
break;
}

return results;
}

/**
Expand All @@ -30,6 +58,9 @@ 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;
if (getWinningMove(handSignOfPlayer1).equals(handSignOfPlayer2)) {
return handSignOfPlayer2;
}
return 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,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;
Integer count = 0;
for(Object object : objectArray){
if(object.equals(objectToCount)){
count++;
}
}
return count;
}

/**
Expand All @@ -21,7 +31,16 @@ 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<Integer> arrayList = new ArrayList<>();
for(Object object : objectArray){
if(!object.equals(objectToRemove)){
arrayList.add((Integer) object);
}

}
// return null;
return arrayList.toArray(new Integer[0]);

}

/**
Expand All @@ -30,7 +49,20 @@ 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;
Object results = null;
int mostOccured = 1;
for(int i = 0; i<objectArray.length; i++){
int amountOccured = 0;
for(int j = 0; j <objectArray.length; j++){
if(objectArray[i].equals(objectArray[j])){
amountOccured++;
}
}
if(amountOccured > mostOccured){
results = objectArray[i];
}
}
return results;
}


Expand All @@ -40,7 +72,20 @@ 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;
Object results = null;
int leastOccured = 1;
for(int i = 0; i<objectArray.length; i++){
int amountOccured = 0;
for(int j = 0; j <objectArray.length; j++){
if(objectArray[i].equals(objectArray[j])){
amountOccured++;
}
}
if(amountOccured <= leastOccured){
results = objectArray[i];
}
}
return results;
}

/**
Expand All @@ -50,6 +95,20 @@ 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 []results = new Object[objectArray.length + objectArrayToAdd.length];
ArrayList<Integer> results = new ArrayList<>();
int count =0;
for(int i =0; i< objectArray.length; i++){
results.add((Integer) objectArray[i]);
//count++;
}
for(int i =0; i<objectArrayToAdd.length; i++){
results.add((Integer) objectArrayToAdd[i]);
}
return results.toArray(new Integer[0]);
// results.toArray(new Object[0]);

//new Integer [map1.size()]
// return null;
}
}
Loading