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
37 changes: 34 additions & 3 deletions src/main/java/LoopFun.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ public class LoopFun
* @return the factorial of the number
*/
public Integer factorial(Integer number){
return null;
int result = 1;
for (int i = number; i > 0; i--) {
result = result * i;
}
return result;

// if (number==0)
// return 1;
// else {
// return (number * factorial(number-1));
// }
}

/**
Expand All @@ -21,7 +31,18 @@ public Integer factorial(Integer number){
* @return Upper case string of the first letter of each word
*/
public String acronym(String phrase) {
return null;

// String str = phrase.replaceAll("\\B.|\\P{L}", "").toUpperCase();
// return str;

String variable = "";
String[] a = phrase.split(" "); // hello my name > [hello, my, name]
for (int i=0; i<a.length; i++){
variable = variable + a[i].charAt(0);
}
variable = variable.toUpperCase();
return variable;

}

/**
Expand All @@ -37,6 +58,16 @@ public String acronym(String phrase) {
* @return the encrypted string by shifting each character by three character
*/
public String encrypt(String word) {
return null;
char[] chars = word.toCharArray();
String result = "";
for (int i = 0; i < chars.length; i++) {
if(chars[i] <= 'w') {
result += chars[i] += 3;
} else if (chars[i] >= 'x') {
result += chars[i] -= 23;
}
}

return result;
}
}
13 changes: 8 additions & 5 deletions src/main/java/MathUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class MathUtilities{
* @return the sum of the two numbers
*/
public Integer add(Integer baseValue, Integer valueToAdd){
return null;
int sum = baseValue+valueToAdd;
return sum;
}

/**
Expand All @@ -19,7 +20,8 @@ public Integer add(Integer baseValue, Integer valueToAdd){
* @return the sum of the two numbers
*/
public Double add(Double baseValue, Double valueToAdd){
return null;
double sum = baseValue+valueToAdd;
return sum;
}

/**
Expand All @@ -28,7 +30,8 @@ public Double add(Double baseValue, Double valueToAdd){
* @return the half of the number in double
*/
public Double half(Integer number) {
return null;
double answer = number/2;
return (answer);
}

/**
Expand All @@ -37,7 +40,7 @@ public Double half(Integer number) {
* @return true if the number is odd, false if it is even
*/
public Boolean isOdd(Integer number){
return null;
return (number % 2 != 0);
}


Expand All @@ -47,7 +50,7 @@ public Boolean isOdd(Integer number){
* @return the result of the number multiply by itself
*/
public Integer square(Integer number) {
return null;
return (number*number);
}

}
27 changes: 21 additions & 6 deletions src/main/java/StringUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class StringUtilities {
* @return `input`
*/
public String returnInput(String input) {
return null;
return input;
}

/**
Expand All @@ -14,23 +14,30 @@ public String returnInput(String input) {
* @return the concatenation of `baseValue` and `valueToBeAdded`
*/
public String concatenate(String baseValue, String valueToBeAdded) {
return null;
return baseValue + valueToBeAdded;
}

/**
* @param valueToBeReversed value to be reversed
* @return identical string with characters in opposite order
*/
public String reverse(String valueToBeReversed) {
return null;
String input = valueToBeReversed;
StringBuilder answer = new StringBuilder();
answer.append(input);
answer.reverse();

return answer.toString();
}

/**
* @param word word to get middle character of
* @return middle character of `word`
*/
public Character getMiddleCharacter(String word) {
return null;
int length = word.length();
int middle = length/2;
return word.charAt(middle);
}

/**
Expand All @@ -39,14 +46,22 @@ public Character getMiddleCharacter(String word) {
* @return `value` with char of value `charToRemove` removed
*/
public String removeCharacter(String value, Character charToRemove) {
return null;
char[] characters = value.toCharArray();
String result = "";
for(int i = 0; i < characters.length; i++) {
if (characters[i] != charToRemove) {
result += characters[i];
}
}
return result;
}

/**
* @param sentence String delimited by spaces representative of a sentence
* @return last `word` in sentence
*/
public String getLastWord(String sentence) {
return null;
String[] word = sentence.split(" ");
return word[word.length-1];
}
}