From 55e7beb015c63ef83a9e90ecfacd4061ab1585a5 Mon Sep 17 00:00:00 2001 From: c-poteat Date: Tue, 2 Nov 2021 23:24:35 -0400 Subject: [PATCH 1/3] Updated still working on --- .../java/io/zipcoder/StringsAndThings.java | 29 ++++++++++++++---- .../io/zipcoder/StringsAndThings.class | Bin 0 -> 1598 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, 23 insertions(+), 6 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..2891eb5 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -15,7 +15,19 @@ public class StringsAndThings { * countYZ("day fyyyz"); // Should return 2 */ public Integer countYZ(String input){ - return null; + //Count the letters need counter variable + int count = 0; + // Split word in two + String[] parts = input.split(" "); + // Place in a loop to iterate the characters + for (int i = 0; i < parts.length; i++) { + // Check to see if words ends with y or z + if (parts[i].trim().endsWith("y") || parts[i].trim().endsWith("z")) { + count++; + } + + } + return count; } /** @@ -27,10 +39,9 @@ public Integer countYZ(String input){ * removeString("Hello there", "e") // Should return "Hllo thr" * removeString("Hello there", "x") // Should return "Hello there" */ - public String removeString(String base, String remove){ - return null; + public String removeString(String base, String remove) { + return null; } - /** * 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) @@ -39,8 +50,14 @@ public String removeString(String base, String remove){ * containsEqualNumberOfIsAndNot("This is notnot") // Should return true * containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true */ - public Boolean containsEqualNumberOfIsAndNot(String input){ - return null; + public Boolean containsEqualNumberOfIsAndNot(String input) { + int one = (input.split("is", -1).length) - 1; + int two = (input.split("not", -1).length) - 1; + if (one == two) { + return true; + } else { + return false; + } } /** diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class new file mode 100644 index 0000000000000000000000000000000000000000..ec2c2fce9db7eb592489abff4b058ba22657455b GIT binary patch literal 1598 zcmah}O;giQ6g@9Vn^2-)5mW@k53~iLeqcorR1mO=uz=AKSD{3RmZYXB4z6AK4|L_Y zajP42T<`ESrn#tZ5&?dbVTcBmuaqYS4`m*gW zTFWJ_q-VXNRl0Baj-1DfTCnC+1bSv2FZaSJ7kSptEd;*fu2yckD~oF~7!}ZqUeygA zE(x5;%s#O;tX#=*SL4jlY~5194eV9h=NaMfUl2$*Zn+vr0e>CjW(dr&Z219|v^{E+ zwQnJ?icjxZo*P(>TbX)R zwMvnP^N$PCk2#NZ?B&3O=ap>BC9>+d1XhFRo`A7hsNA;7!8l!jgRr za{Z1#*Z*29(7M~4`Q;~ek%iVR?bw{CluORPJZRWDjhAU%;9#bq_lE7RR313N8cT1` z!7MM_fn8zo-QsoJuu4^X{;@zurce*Od;2mC;0oD>66+Y^-bvi0dfc6!;yCv4O_jeS z_?DrS&jXz0I0}x5{!b7e87N4{Nq~+v#%7d&gJ|cB6gb4EJiN{91jp;@*g#s@f;y+> zwRUZA`yKiR+qDZ@(9(%5B;O#tGu1hLjpR#3ywt?|U*Ebu!}vf5HKgq!B}l4}s);mh zID+%& xu)++Zs9GK32P>8B&DM0~Ia3-|ITMm}M7uQ-B_ 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..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?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 From 8128ed62a98bf756db58c4263ec0ebb4a10107e6 Mon Sep 17 00:00:00 2001 From: c-poteat Date: Wed, 3 Nov 2021 00:13:03 -0400 Subject: [PATCH 2/3] One more problem left --- .../java/io/zipcoder/StringsAndThings.java | 54 ++++++++++++------ .../io/zipcoder/StringsAndThings.class | Bin 1598 -> 1897 bytes 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index 2891eb5..baa02aa 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -11,10 +11,10 @@ public class StringsAndThings { * but not the 'y' in "yellow" (not case sensitive). We'll say that a y or z is at the end of a word if there is not an alphabetic * letter immediately following it. (Note: Character.isLetter(char) tests if a char is an alphabetic letter.) * example : countYZ("fez day"); // Should return 2 - * countYZ("day fez"); // Should return 2 - * countYZ("day fyyyz"); // Should return 2 + * countYZ("day fez"); // Should return 2 + * countYZ("day fyyyz"); // Should return 2 */ - public Integer countYZ(String input){ + public Integer countYZ(String input) { //Count the letters need counter variable int count = 0; // Split word in two @@ -34,21 +34,22 @@ public Integer countYZ(String input){ * Given two strings, base and remove, return a version of the base string where all instances of the remove string have * been removed (not case sensitive). You may assume that the remove string is length 1 or more. * Remove only non-overlapping instances, so with "xxx" removing "xx" leaves "x". - * + *

* example : removeString("Hello there", "llo") // Should return "He there" - * removeString("Hello there", "e") // Should return "Hllo thr" - * removeString("Hello there", "x") // Should return "Hello there" + * removeString("Hello there", "e") // Should return "Hllo thr" + * removeString("Hello there", "x") // Should return "Hello there" */ public String removeString(String base, String remove) { - return null; + return null; } + /** * 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 + * containsEqualNumberOfIsAndNot("This is notnot") // Should return true + * containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true */ public Boolean containsEqualNumberOfIsAndNot(String input) { int one = (input.split("is", -1).length) - 1; @@ -64,11 +65,15 @@ public Boolean containsEqualNumberOfIsAndNot(String input) { * 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 + * gHappy("xxgxx") // Should return false + * gHappy("xxggyygxx") // Should return false */ - public Boolean gIsHappy(String input){ - return null; + public Boolean gIsHappy(String input) { + if (input.contains("gg")) { + return true; + } else { + return false; + } } @@ -76,10 +81,21 @@ public Boolean gIsHappy(String input){ * 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. * example : countTriple("abcXXXabc") // Should return 1 - * countTriple("xxxabyyyycd") // Should return 3 - * countTriple("a") // Should return 0 + * countTriple("xxxabyyyycd") // Should return 3 + * countTriple("a") // Should return 0 */ - public Integer countTriple(String input){ - return null; + public Integer countTriple(String input) { + int counter = 0; + char c = 0; + for (int i = 0; i < input.length()-2; i++) { + c = input.charAt(i); + if (c == input.charAt(i + 1) && c == input.charAt(i + 2)) { + counter++; + } + + } + return counter; } -} + + +} \ No newline at end of file diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class index ec2c2fce9db7eb592489abff4b058ba22657455b..30657bf441c52adf88be6b0f6d7bfd4faf46e669 100644 GIT binary patch delta 958 zcmah{OHUJF6g_ul%8X?!2)3d;EH7y(QWfO=t_l@Y6i_Ib*wm&#$Pl5J=%yR~fa%Je zapM+af{hE@>&Cy~A8=tJdcK(k-8sqJd+zt$IrrRq=g9sZSp0JQ=?FkC*8HeJuZ8P= z^r2sw0Skl54_O%YV+5lX##B6RVZx6|Oj$^%_=Yk!mAPeN+QiJOsUOl(9F(usW@dZO z$!B*2lHr>uYFfuqEzS~$O(bpH#;lDw+~L6s8+UP!;H8Oq8~5=*pl$4`oCSgIZ0AiZ zs`DkD=W;e4;*pJItk_6l^~0t%Ed_y<*>>{j4QE$SADP=sKTpTE(oQa(SWoXPWS{M2 zolJH(ni5oOWu07poy?JFl3|7klX-y=Nk$WB#u<)7Jrxj8F>R1hoL=aCogX3Z2{eSt zNr2gaa|~=R19dphNN@r5w85fb%uA@aWV9AkRxf_!6`VK5#q=PT5Ni~K^vD8jte zaEh~SMhkSbGP4TCF>Eo>CT-eJ(g@mdNtNK`1ienL$$_%}sEfJc!o2NJ7oIwWI^1ds zMTj&KMA50}icP-0f@&|sB0xVXF+e=Xeuk)Q#3k%>)wiGUwU^abvhSFyK19V`M4oyR z@(W>6W4!E@A@wrLYV@_Sn$w2}yoP0zU?1ou6l~Rp?)DLIJDcG+k_cedEg$l}J1JjV zF0TfqLjo+*?aiMDpQ%-KGOmy6V|t$vG-8LS@;!ZvSS)B9qI#^6-grXv1~m%%3SLmL zugSh4?|y%4D8c$GsRb7Kl>8NPr})pTa_eijipSh=igQZ4GS#+C^!#Vrad%z@hH-@q W?!4;wljz4VMWoBy^)(jM(DMh(;cOBB delta 663 zcmaiw%}x|i5QV?GGh??y3xYEK4KNA=;~?PAIDmlsh@!GFftMg8y3mbo*!TjZw}fZV zupn_k;#Sr?gfHO2MB=IL2{AFzUR0gBb^4rh@AvMbWaZoGmm{FXdYNt}VkXN>ao5Ye znET!z#I(vhq#ZNu^GwWanMce;%ttKjZvL>rblr~AMyRj$aM7?@#N&iTmJ*g((ZTzK zC#(v5h-rWqwxC8yNDNl{?e%K?o|)IhK6l$lM71a-#H9vtM+P|QaANd z^AP(i5a{cWAmWm6k`uU0zb2!?71iGKWAT;sr60?+B<%`icC<3E~bTN#G0kXTqfAe($~-Q>Yemm>SI~@iV`=3^7Ik* rOUeBeZ|63dv|m>d{z|>Qmbp~&^_ffPxERg+b^j@{@gI$Gx8}}oGki3f From b227e571fdf9d850a71dc04cbe7dcec46be2fe8f Mon Sep 17 00:00:00 2001 From: carnell Date: Wed, 3 Nov 2021 08:40:06 -0400 Subject: [PATCH 3/3] Assignment completed --- .../java/io/zipcoder/StringsAndThings.java | 125 ++++++++++++------ .../stringsandthings/GIsHappyTest.java | 13 +- .../io/zipcoder/StringsAndThings.class | Bin 0 -> 2286 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, 91 insertions(+), 47 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..5008c95 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -1,5 +1,6 @@ package io.zipcoder; +import java.util.regex.Pattern; /** * @author tariq @@ -11,58 +12,100 @@ public class StringsAndThings { * but not the 'y' in "yellow" (not case sensitive). We'll say that a y or z is at the end of a word if there is not an alphabetic * letter immediately following it. (Note: Character.isLetter(char) tests if a char is an alphabetic letter.) * example : countYZ("fez day"); // Should return 2 - * countYZ("day fez"); // Should return 2 - * countYZ("day fyyyz"); // Should return 2 + * countYZ("day fez"); // Should return 2 + * countYZ("day fyyyz"); // Should return 2 */ - public Integer countYZ(String input){ - return null; - } + public Integer countYZ(String input) { + //Count the letters need counter variable + int count = 0; + // Split word in two + String[] parts = input.split(" "); + // Place in a loop to iterate the characters + for (int i = 0; i < parts.length; i++) { + // Check to see if words ends with y or z + if (parts[i].trim().endsWith("y") || parts[i].trim().endsWith("z")) { + count++; + } + } + return count; + } /** * Given two strings, base and remove, return a version of the base string where all instances of the remove string have * been removed (not case sensitive). You may assume that the remove string is length 1 or more. * Remove only non-overlapping instances, so with "xxx" removing "xx" leaves "x". - * + *

* example : removeString("Hello there", "llo") // Should return "He there" - * removeString("Hello there", "e") // Should return "Hllo thr" - * removeString("Hello there", "x") // Should return "Hello there" + * removeString("Hello there", "e") // Should return "Hllo thr" + * removeString("Hello there", "x") // Should return "Hello there" */ - public String removeString(String base, String remove){ - return null; + public String removeString(String base, String remove) { + String one = base + remove; + one = (one.replace(remove, "")); + return one; } + /** + * 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){ + // Place input into a split string variables + int one = (input.split("is", -1).length) - 1; + int two = (input.split("not", -1).length) - 1; + // If string equals "is" and "not" return true + if (one == two) { + return true; + } else { + return false; + } + } - /** - * 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; - } + /** + * 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) { + // Check if input contains consecutive string + if (input.contains("gg")) { + // If true return true + return true; + } else { + // or return false + return false; + } + } - /** - * 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; + /** + * 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. + * example : countTriple("abcXXXabc") // Should return 1 + * countTriple("xxxabyyyycd") // Should return 3 + * countTriple("a") // Should return 0 + */ + public Integer countTriple (String input){ + // Setup counter to count result + int counter = 0; + // Setup char variable + char c = 0; + // Setup for loop to iterate through characters + for (int i = 0; i < input.length()-1; i++) { + // Find characters + c = input.charAt(i); + System.out.println(c); + // If character equals another characters run counter + if (c == input.charAt(i + 1) && c == input.charAt(i + 2)) { + counter++; + } + } + return counter; + } } - /** - * 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. - * example : countTriple("abcXXXabc") // Should return 1 - * countTriple("xxxabyyyycd") // Should return 3 - * countTriple("a") // Should return 0 - */ - public Integer countTriple(String input){ - return null; - } -} diff --git a/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java b/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java index 020cd3d..daa9c16 100644 --- a/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java +++ b/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java @@ -8,32 +8,33 @@ /** * @author leon on 29/01/2019. */ -public class GIsHappyTest { + public class GIsHappyTest { private StringsAndThings stringsAndThings; @Before - public void setup(){ + public void setup() { stringsAndThings = new StringsAndThings(); } @Test - public void gIsHappyTest1(){ + public void gIsHappyTest1() { Boolean actual = stringsAndThings.gIsHappy("xxggxx"); Assert.assertTrue(actual); } @Test - public void gIsHappyTest2(){ + public void gIsHappyTest2() { Boolean actual = stringsAndThings.gIsHappy("xxgxx"); Assert.assertFalse(actual); } @Test - public void gIsHappyTest3(){ + public void gIsHappyTest3() { Boolean actual = stringsAndThings.gIsHappy("xxggyygxx"); Assert.assertTrue(actual); - } + + } } diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class new file mode 100644 index 0000000000000000000000000000000000000000..ff37c60b0f838c59900b69df34f9a7717e50bfe3 GIT binary patch literal 2286 zcmaJ>T~`xV6y0|+Fd>YfiGd=-Vk;Ux0u?Dm16T-B(_+vuK^XxTY| zrcxnq@%GjD!f{CNFxmg;wJn1ysh^5jY?3Kj|05c>>s%?j1Th@qs|lv^Po* zEO$#FdRn%%ATIFEvk-a^({NG8hv*eJcZ@4-yJpTT3TS&qzHBaT3UtKN_1S%oq=t_K zI*)I970s5d{DxT!;SvJ!)u-bMu97;VP#`#g#A&!r6z7LY$`JiJ1|%0j*YR=$F(kmM zLm1XEf=>vxXcqED))bhl51-mHic98h*|f7}vMxu%etm6zSArN7P^^+nF(w=PsX)9w zuo|GSuqCx?_38cnWDwMtlFP~bpX->xEUV8t zwrf~+NuawPN@Fc+^2(f!+n6WkdDG5GEl{p$d2mNZ8ej4tOJZgyNtLZlwO|2vHDq)w z;$EYI_e-ux`30OZoueLumNRmX!gk4lY3#5=Ut>wbvW{=CA`qzxqS1%_DaadnR;+G6JBt#Mt;R8 zT5|1gs_vG>OBWaZFKCiLvQF7{SJ(by8tXK2By*07#V5@3xS8#!2B;5 zMVCk-rwq2hnI+fAKDlcYs<1V1y7Z#CQ|{QftT|xJ@3%{h9Lsgv=^b#jxuZ~TF`|Ex^a!)&@tLKIo=Y^7*pyP z#$y;zWpW>wwAPU&GzC-G;HknG<1n$w=s9|}Lp_8pG;E2>%3lm4U}4*@Wrt2OTcKLDDt!vdWWz> zE5M{S96$9>e(Ju#@HM4^>j&xv`5gDn>7Lk21l4z#coUE>ruE3`sB(V;t)!*{lY}va zUXmb5@}Tt9p!E6FwBiB*NNPGrM}d|{jRx^IdWF=&ZVlH%x=GDM2E$Vo+A!km+E6~yhK>qO`cuT(jSdlx>G}3sa lsref8c^|rhIh3lzshEX}vQM0jz#%jt#C1A#h$@`C^X 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..fd51ca8fedfb7c8ed1e9a115ba0ce88426a4f3ed GIT binary patch literal 1323 zcmb7DYflqF6g|@dTb31QQ3R#POK6L-^6*(h1R@DZQxa*K$hT=3>NLwN?!$op%0$6v z;t%jg8Sm^?T0t-*o4a@J%sJ=YJ9mEm`t}3B3Z9!tAZeh>LN|IC2Ali?w;iq;_I9l) z>H$N~OQ~eA%8<#6@T6+^Yih6ZPCF(HBzw^Z%fJl_{TN_a z?F9HSfUCVA0@xd_3b<7M>-Qmd%Hcsxc-#A1nz8H#72#73gDudR3d4A*lk|KR#T3#E zeUy?vL7#F1o!5|so4Cc0tzRX{FqbQ}`w&wX^Btje*L4I}MH9C%Vqnz59o%I|w?VBF z3|1{ZTjfqDq8{#=$YR{UJqr_sGLf?#E|%^;e^>e|trSZeIl9A;ajKPzCZpR4E(MSyPl552UL|hEh1|!@Aga zJwd<$p=V;tFUNzhNYlvc0fiWb{&64F%nlYkIu|*XF0d|B_jcUStBXykn=$*}fn3lR zjY%5v1id0gmd2dCZu03FkEAe%0*4AF+rjUNtHyJ20xkUcBo6rZr$CI>c28k zA)5FD{87et+uBwNF=0QPJ##tlGv}O{U%$Wq1h9?A34{>V5YZ7uOdxeEPo+_lcGcJ~ zA1l)rh&{Dz%YP;i&SXm(;sP_4V|=perc+U_ap1d_UG;YCO7VT*B%mQYgkk6!Zs@p) zq`+E#fY%O?cExW67`slx_KU7nuc@N)NKAFMbTtL$3jGonnfU}pkk&A&V+`X0BfTv4 zY+qHCE1;dqT0`w02~1@6vW0;i`8aL~49T*2cz8$~0*Nf#Vb)=JW~f^lau!Uhn#{!eZH*PgsU z)Kh+=E-?9qjk8Wv$?`0!?%1~DOW$&AiW1mO_qjT9T*bgtUmb&1ZwSOyv(9U#DgvW@ zxpvydn3yzumWRQ8ib3!tdYglYErG;=({N4o(h3SOcHy?I2NwYgyssfX2tmsmOD{^F zFM{?SM+W~Qn9ZF*e5Mn^3T?0q#F3%Z+Z&KYjw69pu7+B{PY`ac>A4@!-kxFTD-u18 z-~ocrVPbnadPirCYXRkcOLM)e`HoRx&W%UTS(w}xB+?V#aQoHj+Bs%=;%P*;KeJ!Qv^>_bcW#BYk{{1!Qn1= W`AYBt!HWbh5xjgY@I&Su!lOS-rw`!( 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..00174b62d55e91642333b3b0a42687935376fc1a GIT binary patch literal 1372 zcmbtTYflqF6g|@iyVOOwriNSS z6DYU5p*=il|&%eHY^j zCNvZ<$$o67sqgu8P+xIf>99r32!l7De52)_1MZq$iBUy6rJ9O+)WaSN>{Z1Bf!=V@ z>2wYSQmecTfxfC~$#s8!M><=^PK!JFs$Dl)HN!E3b+nnH^`tJJarUx{sR*Q9>G^Ge zk@vhVb6?g>*CgVKW!awLnYKkhlAW~sTJGA8WT6&$7+mlIaZIc2(}sMk$;eLuReo;s z)yalHe=Hwe9>IEyx<}t=Y>X;EK1Z~8mUl@YvuXQIUA{E~SF*83Hy=C!O!CPl_$LHM zK3Ya;#{3i$7vm7(0a@ zWEbFnNMZ;ohDkKS)o4gn?m|RVNer;hMLQhi2)HQ`Xxj@MMs|cB@Uat5ikG% 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..65ae362995c5d1b68520c9fded9736c7000f373c GIT binary patch literal 1210 zcmb7DYi|-k6g|VE3)^iARBO>ft*!FXu6_8#m{60d38{%CB=*|?BQDwQl6@HPUzuoY zH1P-cql|YJ3W&Bzzs%m5d(Sy@&)og>`}n69_`kO{a zG(CoyXNF~X&l$q`LR~?OVa2fZPe!+Cw}hh~dX8bW-HO$!eUO0)1>rbmp(&WtFpmX> z!X&^Q0Jzoi0)YPVwfl;9yZxGQNiH$Wj|dsE)k*xcU^#{)-Lltfw|hOQzNp~}t}?{h zLt=(pzB+DfKu|7B9PQb*DY#WuaSh7~(i*Pg219ZT8dfl9jX`alo4yE4IZ}~9R>7)< zn^>a`Y^SYvd@@b1xUO)hDU}C7&5@8u{-{uoVVxmLmzH5o1V{2hQfKslwz7{S_`z(>C5D4@f7Sc z1tAn^m1z*PM5{I^z+K#<9m6JNLjm|H!a+_e{($oC6!EW6#~kt}0+Pg%n&8ofJUZp1 z%KdZD-GV zyL%w(fk5w5<*4A9K)P6}Wswt@RIc?|9o5~2^sJr0Q_h~h=`^bQI>;l7bRYU*WO2>F zbqokBB@6txz;+rzRA6n(L-$z5I#uZtIoR5BCMqyhNorh#Zsaf|klT`lU|)JNhZ_R@ zTe8`7+ldjLpHqFhQ3GQb7cjg8Sm1H7a^8Fl*yzlZI#YSv!ekb=4NPI0hj+a_>ma0O z)~4@EkNp^S6ukTx+D%_zK1qsgPLf)gQZ0uW-BjF#m&08F!QN*1IT6Ubp#K5`73Ih` z;o+|Is`hS^8METn?PksPl%BVe8JbPB^`DI`n=k(r8v;GP48kLU@$JwF)S;{?Ur~0` zaooTTlQFD8@i~&ZeBLK9?&GZn2^-9 zT?JRWQPu?VJ8tOJ_7=ZoXbv{DFycaT6JC8s*k8b~TP+Ohk}ET-<`BiMDW` zm;nM-7^Tn#uSVdtF5p5NeCJZ|6fx5jEf73&CGdI|u-OLRyA(W2@EpPO1Q)Lae!#v{ Gc=!+GL<^b# literal 0 HcmV?d00001