diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index 073467a..04524e0 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -15,7 +15,14 @@ public class StringsAndThings { * countYZ("day fyyyz"); // Should return 2 */ public Integer countYZ(String input){ - return null; + int count = 0; + String stringArr[] = input.split(" "); + for(String word: stringArr) { + if(word.charAt(word.length() - 1) == 'y' || word.charAt(word.length() - 1) == 'z' ) { + count++; + } + } + return count; } /** @@ -28,7 +35,8 @@ public Integer countYZ(String input){ * removeString("Hello there", "x") // Should return "Hello there" */ public String removeString(String base, String remove){ - return null; + String result = base.replaceAll(remove, ""); + return result; } /** @@ -40,7 +48,29 @@ public String removeString(String base, String remove){ * containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true */ public Boolean containsEqualNumberOfIsAndNot(String input){ - return null; + int countIs = 0; + int countNot = 0; + int index = 0; + while (true) { + index = input.indexOf("is", index); + if (index != -1) { + countIs ++; + index += "is".length(); + } else { + break; + } + } + index = 0; + while (true) { + index = input.indexOf("not", index); + if (index != -1) { + countNot ++; + index += "not".length(); + } else { + break; + } + } + return countIs == countNot; } /** @@ -51,7 +81,15 @@ public Boolean containsEqualNumberOfIsAndNot(String input){ * gHappy("xxggyygxx") // Should return false */ public Boolean gIsHappy(String input){ - return null; + boolean result = true; + for (int i = 0; i < input.length(); i++) { + if (input.charAt(i) == 'g'){ + if (input.charAt(i-1) != 'g' && input.charAt(i+1) != 'g') { + result = false; + } + } + } + return result; } @@ -63,6 +101,13 @@ public Boolean gIsHappy(String input){ * countTriple("a") // Should return 0 */ public Integer countTriple(String input){ - return null; + int count = 0; + for (int i = 0; i < input.length()-2; i++){ + char x = input.charAt(i); + if(x == input.charAt(i+1) && x == input.charAt(i+2)) { + count++; + } + } + return count; } } diff --git a/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java b/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java index 020cd3d..9c150d9 100644 --- a/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java +++ b/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java @@ -33,7 +33,7 @@ public void gIsHappyTest2(){ @Test public void gIsHappyTest3(){ Boolean actual = stringsAndThings.gIsHappy("xxggyygxx"); - Assert.assertTrue(actual); + Assert.assertFalse(actual); } } diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class new file mode 100644 index 0000000..0cf0ddb 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..3bc2f6c 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