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 10 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
Binary file added .DS_Store
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/main/.DS_Store
Binary file not shown.
Binary file added src/main/java/.DS_Store
Binary file not shown.
Binary file added src/main/java/com/.DS_Store
Binary file not shown.
Binary file added src/main/java/com/zipcodewilmington/.DS_Store
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,37 @@ 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];
}

/**
* @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
@@ -1,5 +1,10 @@
package com.zipcodewilmington.assessment1.part1;

import java.sql.Array;
import java.util.Arrays;
import java.util.Locale;


/**
* Created by leon on 2/16/18.
*/
Expand All @@ -9,23 +14,45 @@ public class BasicStringUtils {
* @return string with identical content, and the first character capitalized
*/
public static String camelCase(String str) {
return null;
// String[] arr = str.split(" ");
// System.out.println(arr[0].toUpperCase(Locale.ROOT));
// String temp=arr[0].toUpperCase(Locale.ROOT);
// arr[0]=temp;
// String result="";
// for(int i=0;i<arr.length;i++){
// result +=arr[i]+" ";
// }
String first = str.substring(1);
char result = str.toUpperCase().charAt(0);
//System.out.println(result);
//System.out.println(first);
String result1 = result+first;

return result1;
}

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

return result;
}

/**
* @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 result = reverse(str);
result=camelCase(result);



return result;
}


Expand All @@ -34,14 +61,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[] cha=str.toCharArray();
for(int i=0;i<cha.length;i++){
char c = cha[i];
if(Character.isUpperCase(c)){
cha[i]=Character.toLowerCase(c);
}else if(Character.isLowerCase(c)){
cha[i]=Character.toUpperCase(c);
}
}
//String result = new String(cha);
return new String(cha);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,39 @@ public class IntegerArrayUtils {
* @return the sum of `intArray`
*/
public static Integer getSum(Integer[] intArray) {
return null;
int result =0;
for (int i=0;i<intArray.length;i++){
result+=intArray[i];

}
return result;
//return null;
}

/**
* @param intArray an array of integers
* @return the product of `intArray`
*/
public static Integer getProduct(Integer[] intArray) {
return null;
int result =1;
for (int i=0;i<intArray.length;i++){
result*=intArray[i];

}
return result;

//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 sum = getSum(intArray);
double result = sum/intArray.length;


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

return temp;
}

/**
* @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 temp=1;
for(int i=1; i<=n;i++){
temp*=i;
}

return temp;
}

/**
* @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 strval=val.toString();
StringBuilder newstr = new StringBuilder(strval);
newstr.reverse().toString();
strval = newstr.toString();
int reult = Integer.parseInt(strval);


return reult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ public class RockPaperSissorsEvaluator {
* @return the respective winning move
*/
public String getWinningMove(String handSign) {
if(handSign == ROCK){
return PAPER;
}else if(handSign==PAPER){
return SCISSOR;
}else if(handSign==SCISSOR){
return ROCK;
}


return null;
}

Expand All @@ -21,6 +30,15 @@ public String getWinningMove(String handSign) {
* @return the respective losing move
*/
public String getLosingMove(String handSign) {
if(handSign == ROCK){
return SCISSOR;
}else if(handSign==PAPER){
return ROCK;
}else if(handSign==SCISSOR){
return PAPER;
}


return null;
}

Expand All @@ -30,6 +48,14 @@ 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 ||
handSignOfPlayer1==PAPER&&handSignOfPlayer2==ROCK ||
handSignOfPlayer1==SCISSOR&&handSignOfPlayer2==PAPER ){
return handSignOfPlayer1;
}else {
return handSignOfPlayer2;
}

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

import java.util.ArrayList;
import java.util.List;

/**
* Created by leon on 2/16/18.
*/
Expand All @@ -11,7 +14,14 @@ 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(Object i:objectArray){
if(objectToCount==i){
counter++;
}
}

return counter;
}

/**
Expand All @@ -20,8 +30,16 @@ 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) {

ArrayList<Integer> arrayList= new ArrayList<>();
for(Integer i:objectArray){
if(objectToRemove!=i){
arrayList.add(i);
}
}
return arrayList.toArray(new Integer[0]);

}

/**
Expand All @@ -30,7 +48,27 @@ 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;
*/
}


Expand All @@ -40,7 +78,37 @@ 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 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 +118,14 @@ 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.out.println(length);
System.arraycopy(objectArray, 0, mergeArray, 0, x);
System.arraycopy(objectArrayToAdd, 0, mergeArray, x, y);

return mergeArray;
}
}
Loading