From 12720cf561f2445755b7dbfad5e28e269823a76e Mon Sep 17 00:00:00 2001 From: cay Date: Sun, 31 Oct 2021 01:50:13 -0400 Subject: [PATCH] lab completed --- .../java/io/zipcoder/StringsAndThings.java | 49 ++++++++++++++++-- .../stringsandthings/GIsHappyTest.java | 2 +- .../io/zipcoder/StringsAndThings.class | Bin 0 -> 2612 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, 45 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..8919389 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -1,6 +1,11 @@ package io.zipcoder; +import com.sun.org.apache.xpath.internal.operations.Bool; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * @author tariq */ @@ -15,7 +20,14 @@ public class StringsAndThings { * countYZ("day fyyyz"); // Should return 2 */ public Integer countYZ(String input){ - return null; + String[] wordsOfString = input.split(" "); + int counter = 0; + for (int i = 0; i < wordsOfString.length; i++) { + if (wordsOfString[i].endsWith("y") || wordsOfString[i].endsWith("z")) { + counter++; + } + } + return counter; } /** @@ -28,7 +40,7 @@ public Integer countYZ(String input){ * removeString("Hello there", "x") // Should return "Hello there" */ public String removeString(String base, String remove){ - return null; + return base.replace(remove, ""); } /** @@ -40,7 +52,19 @@ public String removeString(String base, String remove){ * containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true */ public Boolean containsEqualNumberOfIsAndNot(String input){ - return null; + int inputLength = input.length(); //11 + + String inputWithoutIs = removeString(input, "is"); //"th not" + int inputWOLength = inputWithoutIs.length(); //7 + int diffOfIs = inputLength - inputWOLength; //11-7 = 4 + int numberOfIs = diffOfIs/2; //4/2 2 is the size of "is" + + String inputWithoutNot = removeString(input, "not"); //"this is " + int inputWONotLength = inputWithoutNot.length(); //8 + int diffOfNot = inputLength - inputWONotLength; // 11-8 = 3 + int numberOfNot = diffOfNot/3; //3/3 =1 3 is the size of "not" + + return numberOfIs == numberOfNot; } /** @@ -51,7 +75,15 @@ public Boolean containsEqualNumberOfIsAndNot(String input){ * gHappy("xxggyygxx") // Should return false */ public Boolean gIsHappy(String input){ - return null; + //check if g is to the left or right + boolean isGHappy = false; + Pattern ggs = Pattern.compile("gg"); + Matcher foundGG = ggs.matcher(input); + if (foundGG.find()) { + String goodbyeGG = removeString(input, "gg"); + isGHappy = !goodbyeGG.contains("g"); + } + return isGHappy; //returning true or false } @@ -63,6 +95,13 @@ public Boolean gIsHappy(String input){ * countTriple("a") // Should return 0 */ public Integer countTriple(String input){ - return null; + int counter = 0; + for (int i = 0; i < input.length() - 2; i++) { + if (input.charAt(i) == input.charAt(i + 1) && (input.charAt(i + 1) == input.charAt(i + 2))) { + 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..b377a52 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); //correcting the assertion for test case } } diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class new file mode 100644 index 0000000000000000000000000000000000000000..c0065e06157bf4b04cacdb232ab453de52d34de6 GIT binary patch literal 2612 zcmah~TUXRp7~N-*nS>z-jvWyNiqtAFAgu~jZeCE3%0-1@)m{uUVTcaNn8|qS<;g#x zPcC0veQRGRs}KHwuGO{r-hbj+mF|;dhFGwDn3Ho(zRUjhx4+EqZ-09Y;1qsLqZOBR z%%t%-uIQMR&p93QX)NHXj%)IKT`r3{meSadFLW%YaRXoKxS7T++?LB%X?%@ubbKo< z@5sf}u%aO^kQ%cc+n*3ndU}@y)JeBs2{g~zjx}FhU$ML;bEU+a%&eO?OUtHb%X4(8 z`fGMYpmWxC2cOvGJbk^vMc=cXV&%M3SXz^tQ2{OQRvrK5ErDY_vv0JQsj2VX*PT{#rk`J<3N%<6R#|_bpC!*OODU!o-Kv+j zrfhl0{#$OxrA!PQKpXYbrJ-P;2(l&~8?bSgn7HxWx5kxIE_zfVxRPK0hbg^E-V3EV~Sz3kxLZMe};vS$y>Qq@{uNA~y3 z#Ajf8Y&Fj+m&`mnb1@!xa?SJ>t@~BW$y=kbd3xtQ9(qAaFf8H$Ve)>oqHoRKnFT` z68I2ZT&43St&@D7$z>87Q09~gWmwIs{jXo*NPkv6kx@60e2(T|pW^-*Qco4}R28qb z{_5C-_A{N8AYmso?pwJYKm*b3V}cyt9OwQN6H6ecn9M*AYw3n6(?*cw?jsx_C=Dm@ zF^&>e13tkq+9|XLnxVdhp`llZ&cqvr5pp=ADyC?p&`8hqXY>s;NKkPWazXO0(59YJ zM}Lr#ei+~`!Dz<=I?0SUOzTF*xsuyJdb}@}Y21J@KfuGV+MZPl!^vziSsG69O%vaY zXljAypbqXH(hq3ux*qsLCexY;)CzG(&&JGR~k0Bjjq7ERC@-6Rh?u zL7c-7&hvIMfL;!v)S+LA*h*rGEOirl6Fom=5ej3SCWn&WHa<^smt@?2a^Fqm^w4vN zb{ccEW0-e3&-;m`n~aa5h2GsnCpqs#Vv7kHHJs5fBIHj*D{xM#ZnQ=h{$S=5eTJ0r zO!FpM<_E~z-VwEp0?Ir?J85c`G$q@TnSC4h;CV#Lc>6oVgd$pCL01Xv8ry!Il3Ju* zmssd>K*j_UbrI+o%aGa~s?#zQ(UM@<<0K>zboMOCR2bZBoNU z7AWg_!>ND~aeWX~&lyPOEL&_mpc!~a8#|E;w4)qQnFVGt8avjO=BK0&OI4Q5T z{$z!*F*z8}v_foo>_LGbEH*CB2G~J$eL=R9!H7srkJYOit5-J?3`QcTq!G&BP=)9Z LhhmB@2~7V32L&t@ 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