From dab696e8408c5388d78d081d109b0ff3e1f5dbf9 Mon Sep 17 00:00:00 2001 From: Raymond Date: Thu, 1 Jul 2021 19:13:47 -0400 Subject: [PATCH] Raymond Fitzgerald --- .../java/io/zipcoder/StringsAndThings.java | 83 +++++++++++++++--- .../stringsandthings/GIsHappyTest.java | 2 +- .../io/zipcoder/StringsAndThings.class | Bin 0 -> 2180 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 8 files changed, 74 insertions(+), 11 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..57bb123 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; + String[] arrayOfWords = input.split(" "); + for (int i = 0; i < arrayOfWords.length; i++) { + String word = arrayOfWords[i]; + int numberOfCharactersInWord = word.length(); + int lastIndex = numberOfCharactersInWord -1; + char lastCharacter = word.charAt(lastIndex); + if(lastCharacter == 'y' || lastCharacter == 'z'){ + + count++; + + } + //if the last character of word is equals to y or z + + } + return count; } /** @@ -27,31 +42,68 @@ public Integer countYZ(String input){ * removeString("Hello there", "e") // Should return "Hllo thr" * removeString("Hello there", "x") // Should return "Hello there" */ + // + //nested loop + public String removeString(String base, String remove){ - return null; - } + String answer = base.replaceAll(remove, ""); + return answer; + } +// /** - * Given a string, return true if the number of appearances of "is" anywhere in the string is equal - * to the number of appearances of "not" anywhere in the string (case sensitive) + * Given a string, return true if the number of appearances of "is" anywhere in + * the string is equal to the number of appearances of "not" anywhere in the string + * (case sensitive) * * example : containsEqualNumberOfIsAndNot("This is not") // Should return false * containsEqualNumberOfIsAndNot("This is notnot") // Should return true * containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true */ public Boolean containsEqualNumberOfIsAndNot(String input){ - return null; + //find the number of "is" appearances + //find the number of "not appearances + //compare number of appearances + + int countIs = 0; + int countNot = 0; + int indexOf = input.indexOf("not"); + while (indexOf >= 0){ + input = input.replaceFirst("not", " "); + indexOf = input.indexOf("not"); + countNot++; + } + indexOf = input.indexOf("is"); + + while (indexOf >= 0){ + input = input.replaceFirst("is" , " "); + indexOf = input.indexOf("is"); + countIs++; + } + + + return countIs == countNot; } /** - * We'll say that a lowercase 'g' in a string is "happy" if there is another 'g' immediately to its left or right. + * We'll say that a lowercase 'g' in a string is "happy" if there is another + * 'g' immediately to its left or right. * Return true if all the g's in the given string are happy. * example : gHappy("xxggxx") // Should return true * gHappy("xxgxx") // Should return false * gHappy("xxggyygxx") // Should return false */ - public Boolean gIsHappy(String input){ - return null; + + public Boolean gIsHappy(String input) { + boolean returnMe = 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') { + returnMe = false; + } + } + } + return returnMe; } @@ -62,7 +114,18 @@ public Boolean gIsHappy(String input){ * countTriple("xxxabyyyycd") // Should return 3 * countTriple("a") // Should return 0 */ + /* + * identify the number of 3x repeating characters + * have that number of 3x repeating characters add to a counter + * */ public Integer countTriple(String input){ - return null; + int counter = 0; + for (int i = 1; i < input.length() - 1; i++){ + if(input.charAt(i) == input.charAt(i - 1) && input.charAt(i) == input.charAt(i + 1)){ + + counter++; + } + } + return counter; } } 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 0000000000000000000000000000000000000000..e8f02c159ee60829f9c8e49d902544dea68deb2a GIT binary patch literal 2180 zcmah~O;;OL7=CVMk_lmGAvCpo1gTa&k^<6?NTJXIg_1UeRw!+$3x{NY!E_QQ6Dri> zIiAD6a8VAMZd~XFdt7v{JN*-GU3-qj=gx!>Eh-%5zW3(6_dZ_}etz@gYXDd9B!bfz z4Pz{V>ll}h3Hi7Y!A(qtF(oI{Vce4AjC{<7aXW%Jq&3{pa91F7-LfrrLO|*3UlvfO zi+NMvbjGsHY~|^y=`0zm1+GLh#hg)CHXKXNtBb0;VU-2CGFEYD$13Hx*BM%L9m`%X zPulsV4Oxr{Xt`p=b|0?@^!8;ojV)uSVA$)`&awWwrL^su>!!m!>a(Jgm-oKaFL2KG zpe?LTZy1h|b4{n5wjX-^A}!ERFv@P)&YNEdG|9TwCLpHyX9)x?yHs&Gde8)P!*Pu5 zg*AB!DYZU1>E5PA*T{V~ZwG$9;UPVNu5t9tc3kG7^lUU37I^!b2U83n`Xnm+)+UxFy_nt6fp&XMp$rIGRbU!22a(rzy!W3xB zC{#=-=~*__`F|Yph+~!tM$Vip6sX(@sp;ok442n5YdK}!Sa(&`Q+dHk{RKx}<2+9B z3qt;cKq1h=XOy!cj?^2$#19bPvk0KI+5~7g!&>(n5W`u{1m3|pKDk*W*xkUjyUKVn z8aRNGRZ?n99eBNu)IdzVG#YFR9zacnVj(r3(%OPC?Et}4I2LZ+et`&wojrth17cSd zFAsm}e1*_=JWlZ-45E>B)C1H&Agu(@MhM*m&_f7AoQwOsFFaHoUG2Xmq|k!@9|Sfa0>6^0#SXy&X1tJ zfi5)kh(mmc1`WL$`n17cs5JI>&Vw9RlyPMu8ErT~M0)cL+BuPC zHD-=hcNMDtTQaKG_vlAG{whskPiK4&n)(u|@(NAIR;AFyn{E-u4AIU~+S`LXY4`$%}$t5Ek4JDN%s)mKQG`0L+ap>{?e*x{AWsn(aw%U4wBIYE3~ e2YR>$db9?5v<7;Fk(VyigHHIMM|gMu*Zu;L1f}W# literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..556ec648ddd0173f22453fac00953e644e289eef GIT binary patch literal 1323 zcmb7DZBG+H5Pr5Tv|JA;MG+Jb3PLH$$&0TTA`nSPnvzJ!0H(EUm(>8~*) zi*q%G)FuTo^p~X)mEfc<+$yiz-UP zUTZ@fIIf_?exXsfy$EWNZp0ftxflk^$NU4gY_1Ni4aczsSCo)zLy5>QVJ!WJy3Ang zI)U2|TT&Ne=Ef^6XlfHV3^0sd*8&rL=x4}M!@LRl=)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..3bc2f6c9eca1a534b197f546063f4959106b1867 GIT binary patch literal 1210 zcmb7@X-^YT6o%j17TQh+C`FMfi)_+G8ChI0CWQnwX)uwdiF~_lujMwwOf!pV{Z}Rm zMiYO4KgxLSbZ`m@Bz&1U>-(I0=FXqLKYs(*#tRK&SW049Lkvr4=vYZ%RXGndtf8Qx zh*An=^?sPbqa@aoFc`9~=SZvVR;*U-SQ!lSRcRYvWVdOzgkv0D%I`3YzLJ*oUNgiC z#X3V`j|v$ks?rh%{z*ePHQq2OlB?QHZq~UYl^+HZ-mxS|`2r*yf?F-h(h$a*ckWx> z?e=TJ^@up)3eWE{@Om4M}UE4MVx2QZjq!FSoC~RI*++xrUZQp5%eW^}7IXw5eBIw9s zl416`mFgJB1kKj#wcEX(j>p(YVpGQ!wv%|G<0+oe3Mi|R&y|x_rTsny7>dKv*DjLI z7ajV2qa&IgL+X4(3~Pm>LGw$*gPdOah1kb4#J?jEX{i4NRGXpNNJkHKW3*6>dOb}(}S*1T|)}@FiX>&bLIlh{1u#Z j#L+Hu=7^*E7H+^lEv?Y literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..715f4d39f9991b68f5c866a2734aec430febcc1e GIT binary patch literal 1308 zcmbW0TTc^F6ouDmOFOh9#ZlxULQyVlxr_o{BE|%bhKH&NG);Um)AmRYDKj`1B>pQC z6{Cqiz#nB?GaYQDpb0NC`|PvN`u1LD=I5_(KLD)beilQR&0sEz1ZD?u3G*5jG!!+I z!c;knMJ#Dp*07?%%;0tgcLat#-&OXmw`n)4tuPRnswl_&pbi>NQ@ZBPsr?Os^dn^} z|FJ-_SgHx6p0ZFNUs1Mv8SK}kTea$KW{ir{u-Y}tRpB~Lru>#7#QX~qH(}XL?y?DU zTkboDvcs-Q&nI=jlYVd@FuonwzS@^HpHGl=@Q??_SiV=Sepdx1!+LJNnMM zT<8_=G_cX56lY2`%}C#Oh?HaMi}dz z0$jr=R{~=^oQMuTL^9gb%iocBeT?L1q`Dg6j|HM~tncdRvCeo*nTRy6|IvIy%_MUp z#z3X~2`M9OWWGRqvAFaVgI#e0DHe^gbc}P2v+0QlQs^9xAxX+k;s%?{bEGLo3D$PT yn~uPRGr-vsaPD026fx5jEf73&A@Ix@;PeStKNmbl@I1i_1Q#y^zR9^0xb+*ujR_9` literal 0 HcmV?d00001