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
23 changes: 18 additions & 5 deletions src/main/java/LoopFun.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@


public class LoopFun
{
Expand All @@ -10,7 +9,11 @@ public class LoopFun
* @return the factorial of the number
*/
public Integer factorial(Integer number){
return null;
int factorial = 1;
for (int i = 1; i <= number; i++) {
factorial *= i;
}
return factorial;
}

/**
Expand All @@ -21,7 +24,9 @@ public Integer factorial(Integer number){
* @return Upper case string of the first letter of each word
*/
public String acronym(String phrase) {
return null;
String s = phrase;
String result = s.replaceAll("\\B.|\\P{L}", "").toUpperCase();
return result;
}

/**
Expand All @@ -37,6 +42,14 @@ public String acronym(String phrase) {
* @return the encrypted string by shifting each character by three character
*/
public String encrypt(String word) {
return null;
String encrypt = "";
for (int i = 0; i < word.length(); i++) {
char letter = word.charAt(i);
letter += 3;
if (letter > 'z') letter -= 26;
encrypt += letter;
}
return encrypt;
}
}

}
18 changes: 13 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 half = number * 0.5;
return half;
}

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


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

}
21 changes: 15 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;
String concatenate = baseValue + valueToBeAdded;
return concatenate;
}

/**
* @param valueToBeReversed value to be reversed
* @return identical string with characters in opposite order
*/
public String reverse(String valueToBeReversed) {
return null;
// Declaring a StringBuilder and converting string to StringBuilder
StringBuilder reverseString = new StringBuilder(valueToBeReversed);
reverseString.reverse(); // Reversing the StringBuilder
String result = reverseString.toString(); // Converting StringBuilder to String
return result; // Returns the reversed String
}

/**
* @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 middleOfWord = length / 2;
return word.charAt(middleOfWord);
}

/**
Expand All @@ -39,14 +46,16 @@ public Character getMiddleCharacter(String word) {
* @return `value` with char of value `charToRemove` removed
*/
public String removeCharacter(String value, Character charToRemove) {
return null;
String strNew = value.replace(String.valueOf(charToRemove), "");
return strNew;
}

/**
* @param sentence String delimited by spaces representative of a sentence
* @return last `word` in sentence
*/
public String getLastWord(String sentence) {
return null;
String lastWord = sentence.substring(sentence.lastIndexOf(" ")+1);
return lastWord;
}
}