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
74 changes: 53 additions & 21 deletions src/main/java/LoopFun.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@

import java.util.Locale;
import java.util.Scanner;

public class LoopFun
{
public class LoopFun {

/**
* Given a number, return the factorial of that number.
* For example, given 5, the factorial is 5 x 4 x 3 x 2 x 1 which should return 120.
* @param number
* @return the factorial of the number
*/
public Integer factorial(Integer number){
return null;
}
/**
* Given a number, return the factorial of that number.
* For example, given 5, the factorial is 5 x 4 x 3 x 2 x 1 which should return 120.
*
* @param number
* @return the factorial of the number
*/

/**
* Given a phrase, get the acronym of that phrase. Acronym is the combination of
* the first character of each word in upper case.
* For example, given "Ruby on Rails", this method will return "ROR"
* @param phrase
* @return Upper case string of the first letter of each word
*/
// Getting first test to pass, I know I'm on the right track but must move on to other questions
public Integer factorial(Integer number) {
int sum = 1;
for (int i = number; i > 0; i--) {
sum = sum * i;
System.out.println(sum);
}

return sum;
}


/**
* Given a phrase, get the acronym of that phrase. Acronym is the combination of
* the first character of each word in upper case.
* For example, given "Ruby on Rails", this method will return "ROR"
* @param phrase
* @return Upper case string of the first letter of each word
*/
public String acronym(String phrase) {
return null;
String[] strList = phrase.split(" ");
String ans = "";
for (int i = 0; i <= strList.length -1; i++){
ans += strList[i].toUpperCase().charAt(0);
}
return ans;
}



/**
* To prevent anyone from reading our messages, we can encrypt it so it will only be readable by its
* intended audience. This method encrypt the message by shifting the letter by 3 characters. If the character is
Expand All @@ -37,6 +54,21 @@ public String acronym(String phrase) {
* @return the encrypted string by shifting each character by three character
*/
public String encrypt(String word) {
return null;
// thinking process LONG VERSION......create string of alphabet
// split the alphabet string
// run for loop on "words" String
// for each character of "words" string compare it to its position in alphabet string + 3
// return the new element
// Not really sure how to accomplish this
String alpha = "abcdefghijklmnopqrstuvwxyz";
StringBuilder encWord = new StringBuilder();
for (int i = 0; i < word.length();i ++){
int idx = alpha.indexOf(word.charAt(i));
idx += 3;
idx = idx % 26;
encWord.append(alpha.charAt(idx));
}
return encWord.toString();

}
}
74 changes: 43 additions & 31 deletions src/main/java/MathUtilities.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,55 @@


public class MathUtilities{

/**
* Add two number together
* @param baseValue first number
* @param valueToAdd number
* @return the sum of the two numbers
*/
public Integer add(Integer baseValue, Integer valueToAdd){
return null;
}
public class MathUtilities {

/**
* Add two number together
*
* @param baseValue first number
* @param valueToAdd number
* @return the sum of the two numbers
*/
public Integer add(Integer baseValue, Integer valueToAdd) {

return baseValue + valueToAdd;
}

/**
* Add two number together
*
* @param baseValue first number
* @param valueToAdd second number
* @return the sum of the two numbers
*/
public Double add(Double baseValue, Double valueToAdd) {
return baseValue + valueToAdd;
}

/**
* 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) {
double ans = (number / 2);
return ans;
}

/**
* Add two number together
* @param baseValue first number
* @param valueToAdd second number
* @return the sum of the two numbers
*/
public Double add(Double baseValue, Double valueToAdd){
return null;
}

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

/**
* 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;
public Boolean isOdd(Integer number) {
if (number % 2 == 1) {
return true;
} else {

return false;
}
}


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

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

return input;
}

/**
Expand All @@ -14,23 +15,34 @@ 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 results = "";

for (int i = valueToBeReversed.length() - 1; i >= 0; i--){
results = results + valueToBeReversed.charAt(i);

}
return results;

}

/**
* @param word word to get middle character of
* @return middle character of `word`
*/

// I know im close, still a beginner and trying to figure it all out, had to comment out "getMiddlechar" to run other test
public Character getMiddleCharacter(String word) {
return null;
return word.charAt(word.length() / 2);

}

/**
Expand All @@ -39,14 +51,19 @@ public Character getMiddleCharacter(String word) {
* @return `value` with char of value `charToRemove` removed
*/
public String removeCharacter(String value, Character charToRemove) {
return null;
String s = value.replaceAll(String.valueOf(charToRemove), "");

return s;
}

/**
* @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];

}

}
2 changes: 1 addition & 1 deletion src/test/java/MathUtilitiesHalfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void test3(){
//Given
double expected = 8;

//When
//When ?tests
double actual = utilities.half(16);

//Then
Expand Down