From 1c3f0a85d6b6d4852e904548cd709d5c857e659e Mon Sep 17 00:00:00 2001 From: jgiroso Date: Wed, 30 Jun 2021 21:54:30 -0400 Subject: [PATCH 1/3] halfway through lab. Passed CountYX and RemoveStringTest --- .../java/io/zipcoder/StringsAndThings.java | 47 ++++++++++++++++-- .../io/zipcoder/StringsAndThings.class | Bin 0 -> 2185 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, 43 insertions(+), 4 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..350494d 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -5,7 +5,6 @@ * @author tariq */ public class StringsAndThings { - /** * Given a string, count the number of words ending in 'y' or 'z' -- so the 'y' in "heavy" and the 'z' in "fez" count, * 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 @@ -15,9 +14,20 @@ public class StringsAndThings { * countYZ("day fyyyz"); // Should return 2 */ public Integer countYZ(String input){ - return null; + int count = 0; + String[] arrayOfWords = input.split(" "); + for(String word : arrayOfWords) { + int numberOfCharInWord = word.length(); + int lastIndex = numberOfCharInWord - 1; + char lastChar = word.charAt(lastIndex); + if(lastChar == 'y' || lastChar == '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. @@ -28,7 +38,11 @@ public Integer countYZ(String input){ * removeString("Hello there", "x") // Should return "Hello there" */ public String removeString(String base, String remove){ - return null; + String deleteString = ""; + if(base.contains(remove)){ + deleteString = base.replace(remove, ""); + } else deleteString = base; + return deleteString; } /** @@ -40,7 +54,32 @@ public String removeString(String base, String remove){ * containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true */ public Boolean containsEqualNumberOfIsAndNot(String input){ - return null; + //search for occurrences of "is" and "not" in string + //remove the string of letters so it does not repeat + //tally the number of occurrences for each + String deleteStringIs = input.replace("is", ""); + String deleteStringNot = input.replace("not", ""); + int numberOfIs = 0; + int numberOfNot = 0; + boolean isVsNotComparison = false; + if(input.contains("is") && input.contains("not")) { + input = deleteStringIs; + numberOfIs++; + input = deleteStringNot; + numberOfNot++; + }else if(input.contains("is") && !input.contains("not")){ + input = deleteStringIs; + numberOfIs++; + }else if(!input.contains("is") && input.contains("not")){ + input = deleteStringNot; + numberOfNot++; + } + //compare the number of occurrences + if(numberOfIs == numberOfNot){ + isVsNotComparison = true; + }else isVsNotComparison = false; + + return isVsNotComparison; } /** diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class new file mode 100644 index 0000000000000000000000000000000000000000..419bab4647807917f49d6cf567e9ad431f4c7933 GIT binary patch literal 2185 zcmah}O;a036zq{!T1m(l1d#R<^SKM6Wglf;SD*Xx^Y(;6U9^^ zf&nB|3`Q}8VS(P$Iz_XoZ|Syxx~tV%dSz1}!31I{Wr`BZ3$5DKOPg%v*>ou*a3*0+5!&Cb#k|)rXCxi(BpV0_m zk`kC!GlD5(R9ulnvuB9jwXB-1nUda`mtK26ui~1(uwi9i81<^Pq1#!vMq|$0SlOmg zWT_Mw5V%+}OugLNS=a3qZN0{wSjnntwN=eFJ=#x?Fl6Xr7u>t(MvRcI})A z@UZS!!Gfk!zOpG5Dw>ZidxOJP6bRR}Mzd&c=+EhoT+0It71;d`&Z(FOuq`8J&@k&Q zPD{Y)MIfr#wzgNnX**fnsc}jO|7wGl^7fJS_cf$dT zbkvsNuFi)O>NOgx4Xz5-PM!8QEKZo9m7%R-V^OQu_n6>lx?&r3IVzE5t7TX91w($s zUAm_;c17My-ma^BYvfN5^u+l)&95xKcn1-f{2k&qE`0c`eF#wbMgdXx06s^KUjo;0 zgMXPU@;u$ey%qnhbWA-$xSW|)lFFN0z@H1ogYm#GxSmwv!Rc8w$?(NoC>~Naa^a*J z4_T2R?BS6o|e2I$OukeD(ejg&l_$a=>ELT|!BF|NrXM1rIw}>`|aoolo@?-C9UUKy%_jvh< zFvkoZa~|L>3hd(^PcA_@W@%N$RTUATVxGT(;vM6fe2>rU$`fwP_l}Ie>40G4_gx{e z&k_nt48}&v>8T@p@DsYzQ?ZdFd{jO}AYIO!%8_6$NYIZ-il3$kQxqWMP@i;BPACmx z(V;|SN_2;m{1ogfu3SoC`2Imc_R2;cpyakA9x*Jn*-yvDohFvjv6S15Kd1N|dl_>2 zOfuvwdZtPTipZ1>0^$%eop8S!eu*w8e276e@)EtB#E_E{SK@(J2rIeZA%f2Myhi$z z^+PHT+83sQF`5@AhXEQkM5{71DNCECY10hmY25;;+(()0SIB#ljJHYeDR*p+$#Z;- zA8E22mPME7iDLWhAqex-lA~A*7W1THanzVSON|F$5M!233=#bsVg;QM8Ajlk+wBpd zuAMPRCZaxyyWEkOS4j>UubYq@y_fELr>}$?J?YEW?n{tS`}(~H!}uSJM^4Sv{{TGd Bv;F`8 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..fd51ca8fed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-~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..adda9fb23e3ec978b5af66c10f9a553b1399e24d GIT binary patch literal 1210 zcmb7DYflqF6g|@i+b#>VMUg565s*HVm50w7lVXCJG?+-!M7~Yiv2L^MHv2HG|H?$c zXyOm>M;Y&Im$p_h;mhoux%Zqi_srd&zrOtdu!qMgB8V!8X^3NrA=Tj@xNdT*t-o$` zMAKuKdTLmP_lzN$FVqzz7?uoM|7diZc1t+=k>?mz+pSow+ItzOP!LUG8k&L`4YQbI zD2xN#0f1XAF97H-Ub!!Mx7)7?m*i4men`l$Tphhl_|;3`9+ z9TGEa=BuN|1_b58*wMain}SYkwBgy zDf{a8sf>Wn$#I6cs$q#k|D++D8gH0%lBwEFZq~VD$bEPiBYRzj(jVsi*ZeZw$Q7R7 zWyrqqEzdX+b;C7?vSL}b$34Tgh>_HW4epC~wj&5Qb8fbL#cg^I-t>HKGR*(OX7Xr^ zLn0;_b|x5i$-^VtcbekBkR7MThh|GY6IN;FA~e*DR+>7B;uO4Jt*#Uk-%1NMahDr8rYzz%ka|6FG; u(7Ats&aIKo`lL>dbe2hHHO8t8tJT)&c-El9#U5kJo*jt%<=R9 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..ba429b6dd3d96cc04e52eadd56584350e3570a01 GIT binary patch literal 1308 zcmbW0YflqF6o%hv3oT_8SV1l#6cuR8W#!@}VocCz_)s;0riq`-(vC2s?BZUK_^(V< zj3)j7f0Xf^-4<3_zVK!C%$YgwGw0ozKYxGz2C$Atd8CleB4eNjy#j*=_OWd>ZD-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 From 1e1afec404687d2c11fd1152f13464bf122cfa9f Mon Sep 17 00:00:00 2001 From: jgiroso Date: Thu, 1 Jul 2021 00:57:15 -0400 Subject: [PATCH 2/3] adding GIsHappy complete --- .../java/io/zipcoder/StringsAndThings.java | 53 +++++++++++------- .../stringsandthings/GIsHappyTest.java | 2 +- .../io/zipcoder/StringsAndThings.class | Bin 2185 -> 2349 bytes .../stringsandthings/GIsHappyTest.class | Bin 1210 -> 1210 bytes 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index 350494d..89af581 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -57,29 +57,25 @@ public Boolean containsEqualNumberOfIsAndNot(String input){ //search for occurrences of "is" and "not" in string //remove the string of letters so it does not repeat //tally the number of occurrences for each - String deleteStringIs = input.replace("is", ""); - String deleteStringNot = input.replace("not", ""); + int numberOfIs = 0; int numberOfNot = 0; - boolean isVsNotComparison = false; - if(input.contains("is") && input.contains("not")) { - input = deleteStringIs; - numberOfIs++; - input = deleteStringNot; - numberOfNot++; - }else if(input.contains("is") && !input.contains("not")){ - input = deleteStringIs; - numberOfIs++; - }else if(!input.contains("is") && input.contains("not")){ - input = deleteStringNot; + String currentString = input; + int indexOf = currentString.indexOf("not"); + + while(indexOf >= 0){ + currentString = currentString.replaceFirst("not", ""); + indexOf = currentString.indexOf("not"); numberOfNot++; } - //compare the number of occurrences - if(numberOfIs == numberOfNot){ - isVsNotComparison = true; - }else isVsNotComparison = false; - return isVsNotComparison; + indexOf = currentString.indexOf("is"); + while(indexOf >= 0){ + currentString = currentString.replaceFirst("is", ""); + indexOf = currentString.indexOf("is"); + numberOfIs++; + } + return numberOfIs == numberOfNot; } /** @@ -90,7 +86,24 @@ public Boolean containsEqualNumberOfIsAndNot(String input){ * gHappy("xxggyygxx") // Should return false */ public Boolean gIsHappy(String input){ - return null; + + //if i >= 1, is g in (i+1) or (i-1) + + boolean indexIsG = false; + for(int i = 0; i < input.length(); i++) { + if (input.charAt(i) == 'g') { + if (input.charAt(i + 1) == 'g' || input.charAt(i -1) == 'g') { + indexIsG = true; + } else if (input.charAt(i+1) != 'g'){ + indexIsG = false; + break; + } else if (input.charAt(i - 1) != 'g'){ + indexIsG = false; + break; + } + } + } + return indexIsG; } @@ -101,7 +114,7 @@ public Boolean gIsHappy(String input){ * countTriple("xxxabyyyycd") // Should return 3 * countTriple("a") // Should return 0 */ - public Integer countTriple(String input){ + 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..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 index 419bab4647807917f49d6cf567e9ad431f4c7933..ad95892a94cdfe97b892e545906b48dcc03b6018 100644 GIT binary patch delta 1169 zcmZuwT~Cr>7``6fmk$vWHE5wY*VYU%kxU{8BrBE7@66I95MLdZ=m1?EdE!aOoV0bI z>%^1Va&6XX>#&1$#sdylJ$4{rmAVfXhhiTVIG4 zCA(Iz!io+Xyyz4#XR?dh)3GH1$A#jA(&UQEY?lo_bPL#W+WM1JS{umZ@`Ykp2|Fyf zBw)zot?bxqM!<$=EWah@>n%rI{AtKbeRN1&E)8fG(sW>|$8 zBm4+LF2RplJ=%K|mL=t+;Xg-ya&UoBbnE!*OCjuJVQG4`J-jn)%mrmE@^5cby1PRG%bbA6SzkvR9-R7eds5z zQmbZ|N(`AQT2U;rgH}tcB_>&#Ib;bx*hJEulq|Woya%X%g-I`&X|gZxqTlOQle)cw zdfJPXxJ8ZZ;ry|rMPa~It=NGcsM%J?)a#ZL1O-sX3m# z!%dT?MT)Ia&m|5vk2$R9D3_H5f!Rdu>-cyN(ZBfF*VXkT801`jSJGG8`o^K zD|f6+Y)q=r#2?^aap}f|5zqS`U>7zakNe$or*qGJ?|toYe*g338-PjNJ9NGg0i{s0 zBP5`f%5^6qh}v+;jX}hkNhK!6KJF+pqAw-juI7v7=lRuowNTn_{t(ILS9RynsVDi} ze7)mM*91-Lz%F5ghm5HSv9Vyab1lY#Ex+OEds=((HB|T*FtK7dQY zEd(v(0G@85UFP^SpZ*RGEpD`6u)fdujPM6ep-PE!+-d{V#zA$wRK`aZ15{&>Iz*{J zj2etngGtO%mpPJ|N0$88$b5^OpOWAXJyk5@1y=Bi3YwR&U{USuY_FrRgHai|GcU@_ zx=durOI3 jKjepUFu#TN22-$V-JT#PdDBcgxk%xJBHbG6vgyWObefIO diff --git a/target/test-classes/io/zipcoder/stringsandthings/GIsHappyTest.class b/target/test-classes/io/zipcoder/stringsandthings/GIsHappyTest.class index adda9fb23e3ec978b5af66c10f9a553b1399e24d..feefb49bf0f5d6d7052a34465234c55e266f048c 100644 GIT binary patch delta 15 WcmdnRxr=i{9?N7l7QxB&EY<)jj0C6v delta 13 UcmdnRxr=i{9t)$) Date: Thu, 1 Jul 2021 09:41:25 -0400 Subject: [PATCH 3/3] Strings and Things Lab complete --- .../java/io/zipcoder/StringsAndThings.java | 18 +++++++++++++++--- .../io/zipcoder/StringsAndThings.class | Bin 2349 -> 2486 bytes 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index 89af581..8894f91 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -87,7 +87,6 @@ public Boolean containsEqualNumberOfIsAndNot(String input){ */ public Boolean gIsHappy(String input){ - //if i >= 1, is g in (i+1) or (i-1) boolean indexIsG = false; for(int i = 0; i < input.length(); i++) { @@ -107,7 +106,7 @@ 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 @@ -115,6 +114,19 @@ public Boolean gIsHappy(String input){ * countTriple("a") // Should return 0 */ public Integer countTriple (String input){ - return null; + int numberOfTriples = 0; + //loop through string + //find if charAt(i) == charAt(i+1) and (i+2) + //increase counter by 1 + + for(int i = 0; i < input.length() - 3; i++){ + if(input.charAt(i) == input.charAt(i+1)){ + if(input.charAt(i+1) == input.charAt(i+2)){ + numberOfTriples++; + } + } + } + + return numberOfTriples; } } diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class index ad95892a94cdfe97b892e545906b48dcc03b6018..93831e3310db78934dd933f614b8c0adabb7df36 100644 GIT binary patch delta 281 zcmXYr%Su9F6otS4{J$0!83{V^?*Tdzh(T0GMG0yUbfF+HFPSG0DnfCRMIgRG!zR(B zkzfReXwU;R>P?ylU3M2XthM)Ad$ZSIDu_j1KA)a}IjZ-Owwa8cbdKwOYyEJ$)jU1& z+Yepyrqd-H_86y3oC>p4$xtKDJ_YJ5bHD}-w(!}Jy%No<>(R~20Y(Zuoz*$(21LV+ zTT-qKh`H9(glKOV1qg3jhkeFqW94g<5BQyB` delta 144 zcmdlcyjFB5XT_K5YM2;kicNfkjP-q zki_7~kj&u1kirnakjfCmkj4-SR2R*VHF+&ZpraWBBTyd$0~6y05XoQ-B-wys3=Cxq cHb7DgBFkXQU