diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index 073467a..20c95b6 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -15,7 +15,22 @@ public class StringsAndThings { * countYZ("day fyyyz"); // Should return 2 */ public Integer countYZ(String input){ - return null; + int count = 0; //set count to 0 + String[] splitString = input.split(" "); // create new string array and split it at space + + for (int i = 0; i < splitString.length; i++){ + String splitWords = splitString[i]; // set word at index to splitWords + int wordLength = splitWords.length(); //take length of words to find end + char lastChar = splitWords.charAt(wordLength-1); //lastChar + if (lastChar == 'y' || lastChar == 'z'){ + count++; + } + + } + + + + return count; } /** @@ -28,7 +43,10 @@ public Integer countYZ(String input){ * removeString("Hello there", "x") // Should return "Hello there" */ public String removeString(String base, String remove){ - return null; + String newString = base.replaceAll(remove, ""); //use the remove strings and replaced all matching in base string that matched + return newString; + + } /** @@ -40,7 +58,21 @@ public String removeString(String base, String remove){ * containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true */ public Boolean containsEqualNumberOfIsAndNot(String input){ - return null; + //need count of is to compare to not + //need count of not to compare to is + //need to iterate thru string + //search for is and not + //return true or false if count is equal + + int isCount = 0; + int notCount = 0; + for (int i = 0; i < input.length()-1; i++) { + if (input.charAt(i) == 'i'&& input.charAt(i+1) == 's'){ + isCount++; + } if (input.charAt(i) == 'n' && input.charAt(i+1) == 'o' && input.charAt(i+2) == 't'){ + notCount++; + } + } return isCount == notCount; } /** @@ -50,11 +82,15 @@ public Boolean containsEqualNumberOfIsAndNot(String input){ * gHappy("xxgxx") // Should return false * gHappy("xxggyygxx") // Should return false */ - public Boolean gIsHappy(String input){ - return null; + public Boolean gIsHappy(String input) { + for (int i = 0; i < input.length(); i++) { //stop forgetting its length()!! for loop to iterate thru string + // //if the char at current index i is g and input at next index is g return true + if (input.charAt(i) == 'g' && input.charAt(i + 1) == 'g') { + return true; + } + } return false; //forgot return value for false. if g is happy return true, if not string will return false } - /** * We'll say that a "triple" in a string is a char appearing three times in a row. * Return the number of triples in the given string. The triples may overlap. @@ -63,6 +99,15 @@ public Boolean gIsHappy(String input){ * countTriple("a") // Should return 0 */ public Integer countTriple(String input){ - return null; + int count = 0; + for (int i = 1; i < input.length()-1; i++) { //had to start index at 1 to pass test 2 + if (input.charAt(i) == input.charAt(i+1) && input.charAt(i) == input.charAt(i-1)){ + count++; + } + + } + + + return count; } } diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class new file mode 100644 index 0000000..baa34da Binary files /dev/null and b/target/classes/io/zipcoder/StringsAndThings.class differ diff --git a/target/test-classes/io/zipcoder/stringsandthings/ContainsEqualNumberOfIsAndNotTest.class b/target/test-classes/io/zipcoder/stringsandthings/ContainsEqualNumberOfIsAndNotTest.class new file mode 100644 index 0000000..556ec64 Binary files /dev/null and b/target/test-classes/io/zipcoder/stringsandthings/ContainsEqualNumberOfIsAndNotTest.class differ diff --git a/target/test-classes/io/zipcoder/stringsandthings/CountTripleTest.class b/target/test-classes/io/zipcoder/stringsandthings/CountTripleTest.class new file mode 100644 index 0000000..29d3cfe Binary files /dev/null and b/target/test-classes/io/zipcoder/stringsandthings/CountTripleTest.class differ diff --git a/target/test-classes/io/zipcoder/stringsandthings/CountYZTest.class b/target/test-classes/io/zipcoder/stringsandthings/CountYZTest.class new file mode 100644 index 0000000..27178e4 Binary files /dev/null and b/target/test-classes/io/zipcoder/stringsandthings/CountYZTest.class differ diff --git a/target/test-classes/io/zipcoder/stringsandthings/GIsHappyTest.class b/target/test-classes/io/zipcoder/stringsandthings/GIsHappyTest.class new file mode 100644 index 0000000..97d69c0 Binary files /dev/null and b/target/test-classes/io/zipcoder/stringsandthings/GIsHappyTest.class differ diff --git a/target/test-classes/io/zipcoder/stringsandthings/RemoveStringTest.class b/target/test-classes/io/zipcoder/stringsandthings/RemoveStringTest.class new file mode 100644 index 0000000..715f4d3 Binary files /dev/null and b/target/test-classes/io/zipcoder/stringsandthings/RemoveStringTest.class differ