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 16 commits into
base: feedback
Choose a base branch
from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ZipCodeWilmington Assessment 1

//Jon testing first commit

## **Getting Started**
* Complete each of the asks in each of the `README.md` files found in the [instructions directory](./instructions)
Expand Down
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 Character.toUpperCase(str.charAt(0)) + 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 reverseSb = new StringBuilder(str);
return reverseSb.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;
String reversedString = reverse(str);
return camelCase(reversedString);
}


Expand All @@ -34,14 +37,30 @@ 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;

//StringBuilder to start
StringBuilder result = new StringBuilder(str.length());
//For loop - with if statement to see if character is upper or lower case
for (char c : str.toCharArray()) {
if (Character.isUpperCase(c)) {
result.append(Character.toLowerCase(c));
} else if (Character.isLowerCase(c)) {
result.append(Character.toUpperCase(c));
} else {
result.append(c);
}
}
return result.toString();

//return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,44 @@ public class IntegerArrayUtils {
* @return the sum of `intArray`
*/
public static Integer getSum(Integer[] intArray) {
return null;
//Need to write a method to getSum(Integer[] intArray)

//Initialize first
int sumOfIntegers = 0;
for (Integer num : intArray) {
sumOfIntegers += num;
}

return sumOfIntegers;
}

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

//Initialize
int productOfIntegers = 1;
for (Integer num : intArray) {
productOfIntegers *= num;
}

return productOfIntegers;
}

/**
* @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;
//Need to write a method to getAverage(Integer[] intArray)

//Initialize to get sum
int sumOfNum = getSum(intArray);

//Average = sum / count
return (double) sumOfNum / intArray.length;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,62 @@ public class IntegerUtils {
* @return the sum of all integers between 0 and not including `n`
*/
public static Integer getSumOfN(Integer n) {
return null;
//Write method to getSumOfN(int n)

//Initialize a sum var
int sumOfN = 0;

//for loop to iterate through n
for (int i = 0; i <= n; i++) {
sumOfN += i;
}

return sumOfN;
}

/**
* @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;
// Write method to getProductOfN(int n)

if (n <= 0) {
return 0;
}

//initialize variable for product of n
int productThroughN = 1;

//iterate through
for (int i = 1; i <= n; i++) {
productThroughN *= i;
}

return productThroughN;
}

/**
* @param val integer value input by client
* @return integer with identical digits in the reverse order
*/
public static Integer reverseDigits(Integer val) {
return null;
//Write method to reverseDigits(int val)

//Initialize a reverse var
int reversed = 0;

//Loop
while (val !=0) {
//get last digit of val
int digit = val % 10;
//Add new value to reversed number
reversed = reversed * 10 + digit;

//remove last dig (value / 10)
val /= 10;
}

return reversed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ public class RockPaperSissorsEvaluator {
* @return the respective winning move
*/
public String getWinningMove(String handSign) {
//Need to write a method to get the winning move against a given hand sign

//Utilizing a switch
switch (handSign.toLowerCase()) {
case "rock":
return "paper";
case "paper":
return "scissor";
case "scissor":
return "rock";
}
return null;
}

Expand All @@ -21,6 +32,17 @@ public String getWinningMove(String handSign) {
* @return the respective losing move
*/
public String getLosingMove(String handSign) {
//Need to write a method to get the losing move against a given hand sign

//Utilizing a switch for scenario building
switch (handSign.toLowerCase()) {
case "rock":
return "scissor";
case "paper":
return "rock";
case "scissor":
return "paper";
}
return null;
}

Expand All @@ -30,6 +52,33 @@ 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;

//Given two Strings, named handSignOfPlayer1, and handSignOfPlayer2, representative of the hand signs of two Rock Paper Scissor players,
// return the String representation of the hand sign which would be the victor.

//Need to write a method to figure out the winner between two players based on their respective hand signs (rock, paper, scissor)

String winningMove = getWinningMove(handSignOfPlayer1);

if (winningMove.equals(handSignOfPlayer2)) {
return handSignOfPlayer2;
} else if (handSignOfPlayer1.equals(handSignOfPlayer2)) {
return "Tie!";
} else {
return handSignOfPlayer1;
}



// String winningMove = getWinningMove(handSignOfPlayer1);
//
// //If statement to check if player 1's move equals player 2's move
// if (winningMove.equals(handSignOfPlayer2)) {
// return handSignOfPlayer1; //player1 wins!
// } else if (handSignOfPlayer1.equals(handSignOfPlayer2)) {
// return "Tie"; // Tie - the same hand-sign for both players 1 and 2
// } else {
// return handSignOfPlayer2; //player2 wins!
// }
}
}
Loading