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


public class LoopFun
{
Expand All @@ -10,7 +10,12 @@ public class LoopFun
* @return the factorial of the number
*/
public Integer factorial(Integer number){
return null;
int fact = 1;
for (int index=number; index >0; index--) {
// System.out.println(index);
fact = index*fact;
}
return fact;
}

/**
Expand All @@ -21,7 +26,15 @@ public Integer factorial(Integer number){
* @return Upper case string of the first letter of each word
*/
public String acronym(String phrase) {
return null;
char[] phraseChars = phrase.toCharArray();
String acronym = "";
for (int index = 0; index < phraseChars.length; index++) {
if (phraseChars[index] != ' ' && (index == 0 || phraseChars[index - 1] == ' ')) {
acronym+=phraseChars[index];
}
}
// System.out.println(acronym);
return acronym.toUpperCase();
}

/**
Expand All @@ -37,6 +50,13 @@ public String acronym(String phrase) {
* @return the encrypted string by shifting each character by three character
*/
public String encrypt(String word) {
return null;
char[] shiftChar = word.toCharArray();
for (int in = 0; in < shiftChar.length; in++) {
if (Character.isLetter(shiftChar[in])) {
shiftChar[in] = (char) ((shiftChar[in] + 3 - (int)'a') % 26 + (int)'a');
}
}
word = String.valueOf(shiftChar);
return word;// String og = "";
}
}
14 changes: 9 additions & 5 deletions src/main/java/MathUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class MathUtilities{
* @return the sum of the two numbers
*/
public Integer add(Integer baseValue, Integer valueToAdd){
return null;
return baseValue+valueToAdd;
}

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

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

/**
Expand All @@ -37,7 +37,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;
boolean isOdd = false;
if ((number%2 != 0)) {
isOdd = true;
}
return isOdd;
}


Expand All @@ -47,7 +51,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;
}

}
19 changes: 13 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,28 @@ public String returnInput(String input) {
* @return the concatenation of `baseValue` and `valueToBeAdded`
*/
public String concatenate(String baseValue, String valueToBeAdded) {
return null;
return baseValue.concat(valueToBeAdded);
}

/**
* @param valueToBeReversed value to be reversed
* @return identical string with characters in opposite order
*/
public String reverse(String valueToBeReversed) {
return null;
String revString = "";
for (int in = valueToBeReversed.length()-1; in>=0; in--) {
revString += valueToBeReversed.charAt(in);
}
return revString;
}

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

/**
Expand All @@ -39,14 +44,16 @@ public Character getMiddleCharacter(String word) {
* @return `value` with char of value `charToRemove` removed
*/
public String removeCharacter(String value, Character charToRemove) {
return null;
String res = value.replaceAll("(?i)" + charToRemove, "");
return res;
}

/**
* @param sentence String delimited by spaces representative of a sentence
* @return last `word` in sentence
*/
public String getLastWord(String sentence) {
return null;
String[] words = sentence.split(" ");
return words[words.length - 1];
}
}
4 changes: 4 additions & 0 deletions src/test/java/LoopsFunAcronymTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void test3() {
assertEquals(expected, actual);
}

@Test
public void test6() {
// given
String phrase = "Center Disease Control Whistle Blower";
Expand All @@ -63,6 +64,7 @@ public void test6() {
assertEquals(expected, actual);
}

@Test
public void test7() {
// given
String phrase = "Tuskegee Macon County, Alabama";
Expand All @@ -75,6 +77,7 @@ public void test7() {
assertEquals(expected, actual);
}

@Test
public void test8() {
// given
String phrase = "John Charles Cutler";
Expand All @@ -100,6 +103,7 @@ public void test9() {
assertEquals(expected, actual);
}

@Test
public void test4() {
// given
String phrase = "Tactical Reconnaissance Nuclear Powered Aerospace Platform";
Expand Down