From 8b54ab9406403d7af999c38e682ab706453994c0 Mon Sep 17 00:00:00 2001 From: Rex Date: Sat, 3 Jul 2021 08:38:21 -0400 Subject: [PATCH] finished itgit add .git add .git add .git add . all tests passed --- .../java/io/zipcoder/StringsAndThings.java | 59 +++++++++++++++--- .../io/zipcoder/StringsAndThings.class | Bin 0 -> 1965 bytes .../ContainsEqualNumberOfIsAndNotTest.class | Bin 0 -> 1323 bytes .../stringsandthings/CountTripleTest.class | Bin 0 -> 1321 bytes .../stringsandthings/CountYZTest.class | Bin 0 -> 1372 bytes .../stringsandthings/GIsHappyTest.class | Bin 0 -> 1210 bytes .../stringsandthings/RemoveStringTest.class | Bin 0 -> 1308 bytes 7 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 target/classes/io/zipcoder/StringsAndThings.class create mode 100644 target/test-classes/io/zipcoder/stringsandthings/ContainsEqualNumberOfIsAndNotTest.class create mode 100644 target/test-classes/io/zipcoder/stringsandthings/CountTripleTest.class create mode 100644 target/test-classes/io/zipcoder/stringsandthings/CountYZTest.class create mode 100644 target/test-classes/io/zipcoder/stringsandthings/GIsHappyTest.class create mode 100644 target/test-classes/io/zipcoder/stringsandthings/RemoveStringTest.class 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 0000000000000000000000000000000000000000..baa34daacda973ca10ca0aa91238a4c7d66d2a12 GIT binary patch literal 1965 zcmah|-%}e^6#nk+CL2Pqlr{)8Y12vzBtR%qr2Mi#p^c3&QxI)=a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NW%V=;{-6U$gh95es` literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..29d3cfe89a19ec698f6f56f4b5783c566258b309 GIT binary patch literal 1321 zcmbW0YflqF6o%jFZA-gKDHr7`1(dcRtALt_F+rjUNtHxMgP+WFJCr45w{Ewj`man> zh$j93f0Xgv?Mll{6ZXUGnKN_V=bSS$zkYxJ31AgZQqVD@VK#*bX8MrETncw_FNt~I zlTV?5ViF5UENZx~VM!p<^jyoXHP`Lx&c1I5OqDFh_+&Lqr>b0I``r4PK;oHYTi$bl zXuePuh;4AAK!3@y)tlB~MY%h&Ql}?da!gq-OV{$}p)=;~TZAl~frLp&yUJB2VQe@p z+uL!i2IExIBQ)MrUaKK6`j#u!p(m9k?Re6&9Gjv9x;5jV#q5k1YR_>M12g7X zt%m|h)ov)$Q&oY%(t$jZMqS!9W7GCjO}T!B()3!g&fp%!Fp=|m%NG$V0;z4M<(lf1 z=PIpT z9+&AJ-FmaBTxOulzIgSL7=}vG6 ziBonA<4m%jB~8$Z;4gSG08d>6Cr-hASAxd~9;fI8L6g@4-?<2mo`O?Xf^!7V5Ijrp M+_k{dtUH3-AHtao{r~^~ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..27178e441080925aa59e674cb2fb937740d251ba GIT binary patch literal 1372 zcmbtTYfsZ)7(MT9Eu+c+CxAzIo`;4x1^4qvVXhDTc%WiFj}ppZM$cmb ziz=2>EGsY+JQOH+zH8YHZ^N$d9fg6wRK;?PGpki|>e4lK|EaGFF${aO=gBFPR(pqP1g#~aWdl{StQXfk;EcQyUr>_7@JOD`}-gE zr00_`>q$Ro35>sI);f_@%d?2MVcU*x`j%r8kYsMdI1Z@Hcr6bdS8`CRB{(a@vFujh zhrP$fSPE!&q3>4s~YH9s($^sI|2R@hCndYN}kAiwJb zZcV(ZJxL)hf~q;3#6l(rvE@{{~YPB$Rrryp9c2z6EVTj zVw};KWh}xR|BLBxD#P69P_~l2K<=IX1(}6!P_`GBE}$mxBisZOlg21ijFD)Zr-_J4 z??A*C6t|?@ezNB#P5A_TU`2YX_ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..97d69c05d93af48f51dd343f570612e004b2bfd8 GIT binary patch literal 1210 zcmb7@YflqV5Qg8=7FxCov_%n=i`=9w%F4wn#-x~_CJiRiG?8zo<+vQO>^6Hbt^dkI z!D!+S@JAWvY!`RIK*E>ZnK?7>Gc$Yk_n#lX0Bqu!hGEQSv7jM^`61|7%wb76_cSb{ ztf7Kx4lC+?KZgfdtY%>_6g=ORw&~UEgT|pU7-s6yF+R&q+c^-fv3KEoi(&AEw59)& zAziLC88WXZkzuqhZLu31w}ji^EsG+hy3^)Xle<#+Q842lN`kDMgG5bm`+!cV3FGx! z?+x#CdJW%yhA9NTd-v_oYk3~~@k|b-k?fBf6j!lY0b4}wYpw^6S@zHSw6%LyT zp*3oqxBY-y3}f{p{)rnFw@qW)aV)`YN-rcdBJ??h^$Us{4BDO(xNWf`)x^bQ->ZtC zqktmA)Kx3hF@jO*t=l!tZdb=ctYxvTV*{I6Jks$PPiO^nst%tjXGo>?dK6%&B&Dxh zB+VBO{jPN++CD?>Y(oso<-}6@-+il+2*rCU#yU}uL2vcf*yL6~tDw8FPr&$_)I3kP z1k`wFG+dRHDetQ*l<&uOxaA4V(d8YcOU>x=(qhOOAe+`m&k}hCy_t$uPr<&Bk-``~ z2g6_h4AsZ`Rgt=e9PVI>x;x`chn$&9 oI72ZpQC z6{Cqiz#nB?GaYQDpb0NC`|PvN`u1LD=I5_(KLD)beilQR&0sEz1ZD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