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 29 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,36 @@ public class BasicArrayUtils {
* @return the first element in the array
*/
public static String getFirstElement(String[] stringArray) {
return null;
return stringArray[0];

//return null;
}

/**
* @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];
//return null;
}

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

//return null;
}

/**
* @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];
//return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,31 @@ public class BasicStringUtils {
* @return string with identical content, and the first character capitalized
*/
public static String camelCase(String str) {
return null;
//char firstChar = str.toUpperCase(str.charAt(0);
//String outcome = new StringBuilder(str).setCharAt(0, );
String outcome = Character.toUpperCase(str.charAt(0)) + str.substring(1);
return outcome;
//return null
}

/**
* @param str string input from client
* @return string with identical contents, in the reverse order
*/
public static String reverse(String str) {
return null;
String outcome = new StringBuilder(str).reverse().toString();
return outcome;
//return null;
}

/**
* @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 step1reverse = reverse(str);
String step2camel = camelCase(step1reverse);
return step2camel;
//return null;
}


Expand All @@ -34,14 +42,31 @@ public static String reverseThenCamelCase(String str) {
* @return string with identical contents excluding first and last character
*/
public static String removeFirstAndLastCharacter(String str) {
return null;
//str = str.substring(1,str.length()-1);
StringBuilder sb = new StringBuilder(str);
sb.deleteCharAt(str.length()-1);
sb.deleteCharAt(0);
return sb.toString();
// String outcome = str.replace(str.charAt(0),'');
// return null;
}

/**
* @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();
//loop through the char to reverse each
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);
//return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.zipcodewilmington.assessment1.part1;

import java.util.Arrays;
import java.util.stream.IntStream;

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -9,22 +12,39 @@ 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;
//Integer sum = intArray.stream();
//int sum = IntStream.of(intArray).sum();
//return Arrays.stream(intArray).sum();
//return null;
}

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

/**
* @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 averg = getSum(intArray);
averg /= (intArray.length);
return averg;

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

/**
* @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;
long outcome = 1;
for (int factor = 2; factor <= n; factor++) {
outcome *= factor;
}
return Math.toIntExact(outcome);
//return null;
}

/**
* @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;
// int digits = val;
// StringBuilder newDigits = new StringBuilder(String.valueOf(digits));
// digits = newDigits.reverse();

//return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,31 @@ public class RockPaperSissorsEvaluator {
* @return the respective winning move
*/
public String getWinningMove(String handSign) {
return null;
if (handSign == "rock") {
return "paper";
}
else if (handSign == "scissors"){
return "rock";
}
else return "scissors";
//return null;

}

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

//return null;
}

/**
Expand All @@ -30,6 +46,17 @@ 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 == "rock" && handSignOfPlayer2 == "scissor") {
return "rock";
}
else if (handSignOfPlayer1 == "scissor" && handSignOfPlayer2 == "paper"){
return "scissor";
}
else if (handSignOfPlayer1 == "paper" && handSignOfPlayer2 == "rock"){
return "paper";
}
else return handSignOfPlayer2;

//return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.zipcodewilmington.assessment1.part2;

import java.util.Arrays;
import java.util.stream.Stream;
import java.util.HashMap;
import java.util.Map;
/**
* Created by leon on 2/16/18.
*/
Expand All @@ -11,7 +15,16 @@ 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;
// loop through
int counter = 0;
for (int i = 0; i <objectArray.length; i++) {
// conditional
if (objectArray[i].equals(objectToCount)) {
counter++;
}
}
return counter;
//return null;
}

/**
Expand All @@ -20,8 +33,30 @@ 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(Integer[] objectArray, Integer objectToRemove) {
int x = 0;
for (int i =0; i <objectArray.length; i++){
//check if element i matches value
//use ! to reverse the locic equals
if (!objectArray[i].equals(objectToRemove)) {
//if no match to remove, go to next array element
x++;
}
}
//create empty fixed array
Integer[] fixedArray = new Integer[x];
int y = 0;
//build array with a loop
for (int i=0; i<objectArray.length;i++){
if (!objectArray[i].equals(objectToRemove)){
//as long as no match to remove
fixedArray[y++] = objectArray[i];
}
}
return fixedArray;
//return null;


}

/**
Expand All @@ -30,17 +65,53 @@ 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<Integer, Integer> countMap = new HashMap<>();
int mostFrequent = (int) objectArray[0];
int maxCount = 0;

for (int i = 0; i < objectArray.length; i++) {
int num = (int) objectArray[i];
int count = countMap.getOrDefault(num, 0) + 1;
countMap.put(num, count);

if (count > maxCount) {
mostFrequent = num;
maxCount = count;
}
}
return mostFrequent;
//return null;
}
/**
* @param objectArray an array of any type of Object
* @return the least frequently occurring object in the array
* given an array of objects, named `objectArray` return the least frequently occuring object in the array
*/
public static Object getLeastCommon(Object[] objectArray) {
return null;
public static Object getLeastCommon(Integer[] objectArray) {
int n = objectArray.length;
boolean visited[] = new boolean[n];
int maxFreq = 0, minFreq = n;
int maxElement = 0, minElement = 0;
for (int i = 0; i < n; i++) {
if (visited[i] == true)
continue;
int count = 1;
for (int j = i + 1; j < n; j++) {
if (objectArray[i] == objectArray[j]) {
visited[j] = true;
count++;
}
}
if (count > maxFreq) {
maxElement = objectArray[i];
maxFreq = count;
}
if (count < minFreq) {
minElement = objectArray[i];
minFreq = count;
}
}
return minElement;
}

/**
Expand All @@ -50,6 +121,15 @@ 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 x = objectArray.length;
int y = objectArrayToAdd.length;
Integer[] mergeArray = new Integer[x + y];

System.arraycopy(objectArray, 0, mergeArray, 0, x);
System.arraycopy(objectArrayToAdd, 0, mergeArray, x, y);

System.out.println(Arrays.toString(mergeArray));
return mergeArray;
//return null;
}
}
Loading