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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

.ds_store

*.ctxt
*.class

Expand Down
52 changes: 49 additions & 3 deletions src/main/java/LoopFun.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ public class LoopFun
* @return the factorial of the number
*/
public Integer factorial(Integer number){
return null;
int y = 1;
for (int x = 2; x <= number; x++) {
y = y * x;
}
return y;

// the factorial function can only go up to the number 13.
// \/\/ using ternary operators. kris didn't like it much
// return (number == 1) || (number == 0) ? 1 : number * factorial(number - 1);

}

/**
Expand All @@ -21,7 +30,21 @@ public Integer factorial(Integer number){
* @return Upper case string of the first letter of each word
*/
public String acronym(String phrase) {
return null;
// String[] phraseArray = phrase.split(" ");
// String acronym = "";
// for (int i = 0 ; i <= phraseArray.length-1 ; i++) {
// acronym += phraseArray[i].charAt(0);
// }
// acronym = acronym.toUpperCase();
// return acronym;

String[] sentence = phrase.split(" ");
String result = "";
for (String s : sentence) {
result = result + s.charAt(0);
}
return result.toUpperCase();

}

/**
Expand All @@ -37,6 +60,29 @@ public String acronym(String phrase) {
* @return the encrypted string by shifting each character by three character
*/
public String encrypt(String word) {
return null;
// String alphabet = "abcdefghijklmnopqrstuvwxyz";
// String secretWord = "";
// for (int wloop = 0 ; wloop < word.length() ; wloop++) {
// for (int aloop = 0 ; aloop < alphabet.length() ; aloop++)
// if (word.charAt(wloop) == alphabet.charAt(aloop)) {
// if (aloop+3 >= 26) {
// secretWord += alphabet.charAt(aloop-23);
// } else {secretWord+=alphabet.charAt(aloop+3);}
// }
// }
// return secretWord;
// }
String alphabet = "abcdefghijklmnopqrstuvwxyz";
StringBuilder encword = new StringBuilder();
for (int i = 0; i < word.length(); i++) {
int index = alphabet.indexOf(word.charAt(i));
index += 3;
index = index % 26;
encword.append(alphabet.charAt(index));
}
return encword.toString();
}

//MOD WORKS HERE ON LINE 80 BECAUSE IT WILL LOOP FROM 0 TO 26. IF THE NUMBER WOULD GO OVER 26
//IT WILL LOOP BACK TO 0. CREATIVE WAY TO LOOP BACK AROUND TO THE BEGINNING OF THE ALPHABET.
}
15 changes: 9 additions & 6 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,16 +28,20 @@ public Double add(Double baseValue, Double valueToAdd){
* @return the half of the number in double
*/
public Double half(Integer number) {
return null;
// return number * 0.5; -- THIS WORKED WHILE "number / 2" DIDN'T BECAUSE '2' IS NOT A DOUBLE.
//BELOW IS PROBABLY THE BEST WAY TO DO THIS, EVEN THOUGH MY CODE WORKED.
//THE LESSON IS THAT MY ORIGINAL ANSWER FAILED BECAUSE I WASN'T USING A DOUBLE, I WAS USING AN INT.
return number / 2.0;
}


/**
* 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;
return number % 2 != 0;
}


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

}
45 changes: 39 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,40 @@ public String returnInput(String input) {
* @return the concatenation of `baseValue` and `valueToBeAdded`
*/
public String concatenate(String baseValue, String valueToBeAdded) {
return null;
// return baseValue += valueToBeAdded; -- my original code
//only better because it uses the concatenate method, it makes the code slightly more clear.
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 backwards = "";
// for (int i = valueToBeReversed.length()-1 ; i >= 0; i--) {
// backwards += valueToBeReversed.charAt(i);
// }
// return backwards;

//WOW. LEARN SOME STRINGBUILDER STUFF KYLE

return new StringBuilder(valueToBeReversed).reverse().toString();

}

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

//Wow! All in one line. Even better. If the number of letters, world.length/2 would round UP.

return word.charAt(word.length()/2);
}

/**
Expand All @@ -39,14 +56,30 @@ public Character getMiddleCharacter(String word) {
* @return `value` with char of value `charToRemove` removed
*/
public String removeCharacter(String value, Character charToRemove) {
return null;
// String remove = Character.toString(charToRemove);
// value = value.replace(remove, "");
// return value;

//Wow! all in one line!
//This could also have been done with a for loop and if statement that builds a new string without charToRemove

return value.replaceAll(String.valueOf(charToRemove), "");
}



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

//nailed it! Kris agrees!
//he also mentioned this method:
// ArrayList<String> s = new ArrayList<>(sentence.split(" "));
// return s.get(s.size()-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
14 changes: 14 additions & 0 deletions src/test/java/StringUtilsRemoveCharacterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,19 @@ public void test4(){
assertEquals(expected, actual);
}

@Test
public void test5(){
// Given
String word = "fgamze";
String expected = "gamze";
char charToRemove = 'f';

//When
String actual = utilities.removeCharacter(word, charToRemove);

//Then
assertEquals(expected, actual);
}


}