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

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

/**
Expand All @@ -21,7 +23,30 @@ public Integer factorial(Integer number){
* @return Upper case string of the first letter of each word
*/
public String acronym(String phrase) {
return null;

String[] words = phrase.split("\\W+");
String output = "";
for (int i = 0; i <words.length; i++) {
// System.out.println(words[i]); // tests if words are being split
output += words[i].charAt(0);

}

return output.toUpperCase();
/*
char c = phrase.charAt(0);
String output = phrase;
String OutPut = null;
for (int i = 1; i < phrase.length(); i++) {
if (Character.isWhitespace(phrase.charAt(i))) {
output = output + phrase.charAt(i);
output += phrase.charAt(i+1);
}
OutPut = output.replaceAll("\\s+","").toUpperCase();
}

return OutPut;
*/
}

/**
Expand All @@ -37,6 +62,17 @@ public String acronym(String phrase) {
* @return the encrypted string by shifting each character by three character
*/
public String encrypt(String word) {
return null;
char[] pass = word.toCharArray();
int shiftVal = 3;
for (int i = 0; i < word.length(); i++) {
if (pass[i] >= 120) {
pass[i] -= 23;

} else {
pass[i] += shiftVal;
}
}
String password = new String(pass);
return password;
}
}
20 changes: 14 additions & 6 deletions src/main/java/MathUtilities.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

import java.lang.Math;

public class MathUtilities{

Expand All @@ -9,7 +9,8 @@ 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 +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;

return baseValue + valueToAdd;
}

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

return (double) number /2 ;
}

/**
Expand All @@ -37,7 +40,12 @@ 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 +55,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;
}

}
39 changes: 33 additions & 6 deletions src/main/java/StringUtilities.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import java.lang.StringBuilder;

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

return input;
}

/**
Expand All @@ -14,23 +16,32 @@ public String returnInput(String input) {
* @return the concatenation of `baseValue` and `valueToBeAdded`
*/
public String concatenate(String baseValue, String valueToBeAdded) {
return null;
String baseVal = baseValue;
String output = baseVal.concat(valueToBeAdded);
return output;
}

/**
* @param valueToBeReversed value to be reversed
* @return identical string with characters in opposite order
*/
public String reverse(String valueToBeReversed) {
return null;
// needed to add stringbuilder, no reason to use a costly for loop
StringBuilder str = new StringBuilder();
String input = valueToBeReversed;
str.append(input);
str.reverse();
String output = String.valueOf(str);
return output;
}

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

/**
Expand All @@ -39,14 +50,30 @@ public Character getMiddleCharacter(String word) {
* @return `value` with char of value `charToRemove` removed
*/
public String removeCharacter(String value, Character charToRemove) {
return null;
StringBuilder str = new StringBuilder();
String input = value;
int count = 0;
str.append(input);
for (int i =0 ; i < value.length(); i++) {
if ( value.charAt(i) == charToRemove) {
// output = value.replace(charToRemove.toString(), "");}
str.deleteCharAt(i-count);
// str.replace(i,i,"");
count += 1;
}
}
String output = String.valueOf(str);
return output;
}

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