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: 30 additions & 7 deletions src/main/java/LoopFun.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import java.util.Locale;

public class LoopFun
{
Expand All @@ -10,8 +10,12 @@ 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 *= i;
}
return result;
} //passed

/**
* Given a phrase, get the acronym of that phrase. Acronym is the combination of
Expand All @@ -21,8 +25,13 @@ public Integer factorial(Integer number){
* @return Upper case string of the first letter of each word
*/
public String acronym(String phrase) {
return null;
}
String result = "";
for (String s : phrase.split("\\s")) {
result += s.charAt(0);
}
result = result.toUpperCase();
return result;
} //passed

/**
* To prevent anyone from reading our messages, we can encrypt it so it will only be readable by its
Expand All @@ -37,6 +46,20 @@ public String acronym(String phrase) {
* @return the encrypted string by shifting each character by three character
*/
public String encrypt(String word) {
return null;
}
char[] ch = word.toCharArray();
for (int i = 0; i < ch.length; i++) {
if (ch[i] == 'x') {
ch[i] -= 26;
}
if (ch[i] == 'y') {
ch[i] -= 26;
}
if (ch[i] == 'z') {
ch[i] -= 26;
}
ch[i] += 3;
}
String result = new String(ch);
return result;
} //passed
}
26 changes: 16 additions & 10 deletions src/main/java/MathUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ public class MathUtilities{
* @return the sum of the two numbers
*/
public Integer add(Integer baseValue, Integer valueToAdd){
return null;
}
Integer result = baseValue + valueToAdd;
return result;
} //passed

/**
* Add two number together
Expand All @@ -19,26 +20,31 @@ public Integer add(Integer baseValue, Integer valueToAdd){
* @return the sum of the two numbers
*/
public Double add(Double baseValue, Double valueToAdd){
return null;
}
Double result = baseValue + valueToAdd;
return result;
} //passed

/**
* Get half the value of the number
* @param number the number given
* @return the half of the number in double
*/
public Double half(Integer number) {
return null;
}
Double result = (number.doubleValue() / 2);
return result;
} //passed

/**
* Determine if the number is odd
* @param number the number given
* @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;
}
return false;
} //passed


/**
Expand All @@ -47,7 +53,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;
} //passed

}
36 changes: 23 additions & 13 deletions src/main/java/StringUtilities.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,62 @@

public class StringUtilities {
/**
* @param input value to be returned
* @return `input`
*/
public String returnInput(String input) {
return null;
}
return input;
} //passed

/**
* @param baseValue value to be added to
* @param valueToBeAdded value to add
* @return the concatenation of `baseValue` and `valueToBeAdded`
*/
public String concatenate(String baseValue, String valueToBeAdded) {
return null;
}
String result = baseValue.concat(valueToBeAdded);
return result;
} //passed

/**
* @param valueToBeReversed value to be reversed
* @return identical string with characters in opposite order
*/
public String reverse(String valueToBeReversed) {
return null;
}
StringBuilder sb = new StringBuilder();
for(int i=valueToBeReversed.length()-1;i>=0;i--) {
sb.append(valueToBeReversed.charAt(i));
}
String result = sb.toString();
return result;
} //passed

/**
* @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);
} //passed

/**
* @param value value to have character removed from
* @param charToRemove character to be removed from `value`
* @return `value` with char of value `charToRemove` removed
*/
public String removeCharacter(String value, Character charToRemove) {
return null;
}
String str = value.replace(charToRemove.toString(),"");
return str;
} //passed

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