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 9 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
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,32 @@ public class BasicStringUtils {
* @return string with identical content, and the first character capitalized
*/
public static String camelCase(String str) {
return null;
String subString1 = str.substring(0,1);
String subString2 = str.substring(1,str.length());
String subStringCap = subString1.toUpperCase();

return subStringCap+subString2;
}

/**
* @param str string input from client
* @return string with identical contents, in the reverse order
*/
public static String reverse(String str) {
return null;
StringBuilder revStr = new StringBuilder(str);
return revStr.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 str2 = new StringBuilder(str);
String str2Rev = str2.reverse().toString();
String str2RevCap = camelCase(str2Rev);

return str2RevCap;
}


Expand All @@ -34,14 +43,28 @@ 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 strRemovedEnds = str.substring(1, str.length()-1);

return strRemovedEnds;
}

/**
* @param str a string input from user
* @return string with identical characters, each with opposite casing
*/
public static String invertCasing(String str) {
return null;
String[] individualCharsAsStrings = str.split("");
StringBuilder casedString = new StringBuilder();

for (int i = 0; i < str.length(); i++){
if (!individualCharsAsStrings[i].equals(individualCharsAsStrings[i].toUpperCase())){
casedString.append(individualCharsAsStrings[i].toUpperCase());
}
else {
casedString.append(individualCharsAsStrings[i].toLowerCase());
}
}

return casedString.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,37 @@ public class IntegerArrayUtils {
* @return the sum of `intArray`
*/
public static Integer getSum(Integer[] intArray) {
return null;
// int sum = 0;
// for (int element : intArray){
// sum = sum + intArray[element];
// }
// return sum;
int sum = 0;
for (int i = 0; i < intArray.length; i++){
sum = 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 product = 1;
for (int i = 0; i < intArray.length; i++){
product = product * intArray[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;
int sum = getSum(intArray);
double avg = sum / intArray.length;
return avg;
}
}
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;
int sum = 0;
for (int i = n; i > 0; i--){
sum = 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 product = 1;
for (int i = n; i > 0; i--){
product = product * i;
}
return product;
}

/**
* @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 intString = Integer.toString(val);
// i stole my code from the string utils reverse method i made in step 1;
StringBuilder intStringSBRev = new StringBuilder(intString);
String intStringRevRev = intStringSBRev.reverse().toString();

return Integer.parseInt(intStringRevRev);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,29 @@ public class RockPaperSissorsEvaluator {
* @return the respective winning move
*/
public String getWinningMove(String handSign) {
return null;
switch (handSign){
case (SCISSOR):
return ROCK;
case (ROCK):
return PAPER;
default:
return SCISSOR;
}
}

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

/**
Expand All @@ -30,6 +44,13 @@ 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 (handSignOfPlayer1.equals(getWinningMove(handSignOfPlayer2))){
return handSignOfPlayer1;
}
else if (handSignOfPlayer2.equals(getWinningMove(handSignOfPlayer1))){
return handSignOfPlayer2;
} else{
return "tie";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.zipcodewilmington.assessment1.part2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -11,7 +16,15 @@ 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 @@ -20,8 +33,38 @@ public static Integer getNumberOfOccurrences(Object[] objectArray, Object object
* @return an array with identical content excluding the specified `objectToRemove`
* 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;
public static Integer[] removeValue(Object[] objectArray, Object objectToRemove) {
// ArrayList<Object> objectArrayList = new ArrayList<>();
// int counter = 0;
//
// while(counter < objectArray.length-1){
// if (objectArray[counter].equals(objectToRemove)){
// counter++;
// } else{
// objectArrayList.add(objectArray[counter]);
// counter++;
// }
// }
// return objectArrayList.toArray();
int numberOfOccurances = getNumberOfOccurrences(objectArray, objectToRemove);
int counter = 0;
int arrayIndexCounter = 0;
Integer[] occuranceArray = new Integer[objectArray.length - numberOfOccurances];

while(counter < objectArray.length){
if (objectArray[counter].equals(objectToRemove)) {
counter++;
} else {
occuranceArray[arrayIndexCounter] = (Integer) objectArray[counter];
arrayIndexCounter++;
counter++;

}

}
return occuranceArray;
//i changed the method to return an Integer[] because I was having test issues of the compiler
//parsing my original object[] into an Integer[] for the test
}

/**
Expand All @@ -30,7 +73,24 @@ 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<Object, Integer> map = new HashMap<>();

for (int i = 0; i < objectArray.length; i++){
Integer occurance = map.getOrDefault(objectArray[i], 0);
occurance++;
map.put(objectArray[i], occurance);
}
Integer max = 0;
Object answer =0;

for (Map.Entry<Object, Integer> entry : map.entrySet()){
if (entry.getValue() > max){
max = entry.getValue();
answer = entry.getKey();
}
}

return answer;
}


Expand All @@ -40,7 +100,25 @@ 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;
HashMap<Object, Integer> map = new HashMap<>();

for (int i = 0; i < objectArray.length; i++){
Integer occurance = map.getOrDefault(objectArray[i], 0);
occurance++;
map.put(objectArray[i], occurance);
}
Integer min = 10;
Object answer =0;

for (Map.Entry<Object, Integer> entry : map.entrySet()){
if (entry.getValue() < min){
min = entry.getValue();
answer = entry.getKey();
}
}

return answer;

}

/**
Expand All @@ -50,6 +128,12 @@ 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[] merger = Arrays.copyOf(objectArrayToAdd, objectArray.length+objectArrayToAdd.length);
// System.arraycopy(objectArray, 0, objectArray.length + objectArrayToAdd.length);

Object[] result = Arrays.copyOf(objectArray, objectArray.length + objectArrayToAdd.length);
System.arraycopy(objectArrayToAdd, 0, result, objectArray.length, objectArrayToAdd.length);
return result;

}
}
Loading