From 62e07322797d2c37553603393bace62a2f09aeaf Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 30 Jun 2021 16:53:50 -0400 Subject: [PATCH] Passed all test cases --- .../java/io/zipcoder/StringsAndThings.java | 59 ++++++++++++++++-- .../io/zipcoder/StringsAndThings.class | Bin 0 -> 2220 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, 53 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..598513d 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -1,6 +1,9 @@ package io.zipcoder; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * @author tariq */ @@ -15,8 +18,15 @@ public class StringsAndThings { * countYZ("day fyyyz"); // Should return 2 */ public Integer countYZ(String input){ - return null; - } + int result = 0; + for (int i = 0; i < input.length(); i++) { + if (input.charAt(i) == 'y' || input.charAt(i) == 'z') { + result += 1; + } + } + return result; + } // This one needs refinement - only pass two cases - need more work in the if statement + // This method counts all (given) letters inside of a string /** * Given two strings, base and remove, return a version of the base string where all instances of the remove string have @@ -28,7 +38,9 @@ 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.replace(remove, ""); + + return result; } /** @@ -40,8 +52,31 @@ public String removeString(String base, String remove){ * containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true */ public Boolean containsEqualNumberOfIsAndNot(String input){ - return null; + + Integer resultIs = 0; + Integer resultNot = 0; + for (int i = 0; i < input.length() - 1; i++) { + char is = 'i'; + char is2 = 's'; + char not = 'n'; + char not1 = 'o'; + char not2 = 't'; + if (input.charAt(i) == is && input.charAt(i + 1) == is2) { + resultIs++; + } + if (input.charAt(i) == not && input.charAt(i + 1) == not1 && input.charAt(i + 2) == not2) { + resultNot++; + } + } + if (resultIs.equals(resultNot)) { + return true; + } + return false; } + // This current state of code (input.matches(String) returns test 2 & 3 + // Previous state of code (input.contains(String) returns test 1 + // Interesting... + // But!! If I use input.charAt(i) and type out variables for each letter...I pass 1 and 2 but not 3 /** * We'll say that a lowercase 'g' in a string is "happy" if there is another 'g' immediately to its left or right. @@ -51,7 +86,11 @@ public Boolean containsEqualNumberOfIsAndNot(String input){ * gHappy("xxggyygxx") // Should return false */ public Boolean gIsHappy(String input){ - return null; + String checkValue = "gg"; + if(!input.contains(checkValue)) { + return false; + } + return true; } @@ -63,6 +102,14 @@ public Boolean gIsHappy(String input){ * countTriple("a") // Should return 0 */ public Integer countTriple(String input){ - return null; + input.toLowerCase(); + int result = 0; + for (int i = 0; i < input.length() -2; i++) + { + char possibleSeq = input.charAt(i); + if (possibleSeq == input.charAt(i+1) && possibleSeq == input.charAt(i+2)) + result++; + } + return result; } } diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class new file mode 100644 index 0000000000000000000000000000000000000000..87fe60031d7d8e211562100936a0f18c8b246a32 GIT binary patch literal 2220 zcmah~T~ixX7=BK&$tIh{rnITHkV;#zK=^2p#+Cr(t1YQ~s2~WAGhLQ#SO~izA9Y&2 z@PZ5Pyz)ZFjtn=tTJtc&0k(1VmqZ; zRRVa)km$=+rB>u^(|px1H)o7efJ`r2TkZqP$0Bh36=7fY*9gS7Bo1ZOs4#y$J;xa$@z!=dMp7jsTu3P5jqEW07dcrHiLfJ0KiY7{KrDC&~ z^VT*M=iOS_v~Jt-D)sLg_Db$`oIp~=l#V>^>Ua;+jHzP=vjWgDhxc`SAa6dzyov>R z^AWQw6m%?NNyo=n7HIviRuM=Z6?txT!!pUp$)lqn?_+9*C5{#?r%+w@8kubqHP?;u zm?X3#-${?zH=vRi5yA_;g33 zy8tFGpo#Ag`H6y)k0jTV-1YIv!Xnc3GsI66LTC<@01c-o>%Ia`BgGv7<8`jm_Ix|<^hh|cy%6n?H6pJ2=wGWDo3cRyb#wRy3mbb(TcnjuDQp-+K}MC`F4e&k-K zr~NRKoRQ0HIIE--$&0eKhcAUBD=UmQMo5K(OsPB z9@M%Ipepz1W_e~XaaLOjRMlNvsjJ3(yNG8Or(MsW)>F5e_3U;OGXHruk7M5=raVRb z3BkpW$}rAu0Irj=8%%MKbmy4f5YryUTNptHZj$CvOkxa6n7|j5zNX$cxP!--!XEB= z#NDTLD=M^Ur>{1+c$-p``%PS?q|#G?zjhMX4U?3&BhJ43$}6xe&wics{h+`RdhcRk zLiGKZRvD5kOFfLpb2O>w;a9xiyGm2htD-MB5%L4P;GbaR*ag7WkR5&Hux{9*bJ<;~ zW^E=z(i7hy<`Lvk#S6b#o4p2F=57TEd_vAX^|EgBjqAu$0di?|)oT}tHwN*ye6PxR z>#q;cZ}b`A?I?RhU#d@0gx!+yrpN1_wAU89Xl5^^y;3)f)E~!3>LMcnHob0;?@c1y zA|8h^U0mZnhiwn_05#+Yy~7$PtU`Z%$VTg#j0Tyg?2DrzOCbCVaUnAPj14ec2-p4r DdgisE 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*{I6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