From 850f69e3f7ceb4db2e3d9735722af14dcc2a4c89 Mon Sep 17 00:00:00 2001 From: laura Date: Thu, 1 Jul 2021 16:16:44 -0400 Subject: [PATCH 1/2] Strings and things --- .../java/io/zipcoder/StringsAndThings.java | 107 +++++++++++++++--- .../io/zipcoder/StringsAndThings.class | Bin 0 -> 2284 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, 92 insertions(+), 15 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..37724ec 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -11,25 +11,50 @@ 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) { + int count = 0; + String[] theArray = input.split(" "); + for (int i = 0; i < theArray.length; i++) { + String words = theArray[i]; + int numCharact = words.length(); + int lastIndex = numCharact - 1; + char lastChar = words.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. * 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) { + + return base.replace(remove, ""); + + + + //return null; + + + + + } /** * Given a string, return true if the number of appearances of "is" anywhere in the string is equal @@ -40,7 +65,27 @@ public String removeString(String base, String remove){ * containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true */ public Boolean containsEqualNumberOfIsAndNot(String input){ - return null; +Integer theIs = 0; +Integer theNot = 0; + +for (int theChar = 0; theChar < input.length() -1; theChar ++ ) { + + + if (input.charAt(theChar) == 'i' && input.charAt(theChar + 1) == 's') { + theIs++; + + } + + if (input.charAt(theChar) == 'n' && input.charAt(theChar + 1) == 'o' && + input.charAt(theChar + 2) == 't') { + theNot++; + + } + + +} + + return theIs.equals(theNot); } /** @@ -50,8 +95,19 @@ public Boolean containsEqualNumberOfIsAndNot(String input){ * gHappy("xxgxx") // Should return false * gHappy("xxggyygxx") // Should return false */ - public Boolean gIsHappy(String input){ - return null; + public Boolean gIsHappy(String input) { + + + return input.contains("gg"); +/*int counter = 0; +int gIsHappy = 0; + for (int i = 0; i < in < input.length() -1; i++){ + if (input.charAt(i) == 'g' && input.length() -1 )*/ + + + + + //return input.contains("gg"); } @@ -62,7 +118,28 @@ public Boolean gIsHappy(String input){ * 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; + input = input.toLowerCase(); + for (int i = 0; i <= input.length() - 1; i++) { + if (input.charAt(i) == 'x' && input.charAt(i+1) == 'x' && input.charAt(i+2) == 'x' || + input.charAt(i) == 'y' && input.charAt(i+1) == 'y' && input.charAt(i+2) == 'y' ) { + counter++; + } } + + return counter; + + } // + + + + /// } + + + + + + + diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class new file mode 100644 index 0000000000000000000000000000000000000000..fd0839f28ef9ac4e8daee21e49801fd5a8432937 GIT binary patch literal 2284 zcmah~T~`xV6x}zO$%HTzhz6w)i&_;3h*bm&N<~182Czc0ezau>V;CA{;$(tgAF9@_ z)#Xcnf-L*cmp-&F)YS*y+uzV%(zUAHcP0sAOWTm#IrrT2xzE1CZ?ArN31ASPCD4NR z;}}Vx8>4bLE0=Q#oWfWfAIQylxfz$sg#;!r8OM}VUzE!w4VN`!1!89{+w#T)qTM|U z0?LH5Yzj2zEZdx^tSy=Dys=cICYf{cMsdM#ExE5M6>r5V3mnK<&cFk!l&7ydFz30J zT_}&+%kwKz7!}a+PQ~_a-V!+0om(~5je(+J7pj({Jt0-r_RNCm(nr1TxXTQl44np{ zd6=*(YZEJmYverv!8RI-M%l~S%jSkaT*~s4M-%*63})G-3QbkN5Sn-^=D6z`n*w`o z@0Orx&NK3#Pa7q_Qw>KnToKS+bIn;dgE9op?9$9XgN56xH=ryTWuh7j0t%$_j_nzi zU7osEF^U25vv;!+#Tkc%{~vA_9H(d+w#1sP1qE0RRMOGggVI%Y7d;~GBH zaUF94&@qpXbSy~q4ScNOraU1%B87sE+qk3S6MQPr`Cq&eXxX9C?9!?!xe!v-rqsG) zRc)L+D3^-XzrngIA!0?-E_f^cJ(1TYPkxOvg3_JsA<49LqgXL#?+Ub0u`AY^YnF;e zo}f*Jc_U{vXWpxrcHSHfIliF}N33%wZrR>~Ov`c@z$kLesc`53l+hjn8v>z96_Q5;r zN7Qz88_G~D6;qanw01S6Z9^T3r{XP}&ye8b!4_gqBI1c6zJL8|=L^JsWVonb!f`ZG z-pdpzCTU~BeN4O`U0jdiZC2iab4cSn&o1JSU+NuNw&NI2JD}3C3!Sux`Su4WY4mEv zJJiS7)(BBaLy-+so0HNZ`tk}Oi^DvX4PL;zIKrxq(sCHeE9gSQG4UEF(4e7NL$|+| zPa%NUbW%fl;13of(1YFpHf&;Xst2M(QV4#FwS~hJl|{KJZ=tPkMD5!~gR)4Mo6{q) zcJ)Tp)ZW60x~UWRslJ~_zy1-mzwS5V`}t%1wvXz>3pDPGvKI+fHc1qwC|%+ZuMoSd z{BL+2iC> zj->;vzr(dmTB5tLg^o-*K$>!MCLN%+@eD@-i_I+@s98`>)+{Ld*CNVm@xz!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+?KZgfd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wed, 13 Oct 2021 15:38:23 -0400 Subject: [PATCH 2/2] last --- .../java/io/zipcoder/StringsAndThings.java | 75 ++++++++++-------- .../stringsandthings/GIsHappyTest.java | 2 +- .../io/zipcoder/StringsAndThings.class | Bin 2284 -> 2249 bytes .../stringsandthings/GIsHappyTest.class | Bin 1210 -> 1211 bytes 4 files changed, 45 insertions(+), 32 deletions(-) diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index 37724ec..3cbbdf7 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -17,11 +17,26 @@ public class StringsAndThings { public Integer countYZ(String input) { - int count = 0; + + + String[] words = input.split(" "); + Integer numOfWords = 0; + + for (String word : words) { + if (word.charAt(word.length() - 1) == 'y' || word.charAt(word.length() - 1) == 'z') { + numOfWords++; + } + } + return numOfWords; + } + + + + /*int count = 0; String[] theArray = input.split(" "); for (int i = 0; i < theArray.length; i++) { String words = theArray[i]; - int numCharact = words.length(); + int numCharact = words.length(); // THIS ALSO WORKS int lastIndex = numCharact - 1; char lastChar = words.charAt(lastIndex); if (lastChar == 'y' || lastChar == 'z') { @@ -31,8 +46,11 @@ public Integer countYZ(String input) { } - return count; - } + return count;*/ + + + + //} /** * Given two strings, base and remove, return a version of the base string where all instances of the remove string have @@ -45,12 +63,7 @@ public Integer countYZ(String input) { */ public String removeString(String base, String remove) { - return base.replace(remove, ""); - - - - //return null; - + return base.replace(remove, ""); @@ -70,21 +83,14 @@ public Boolean containsEqualNumberOfIsAndNot(String input){ for (int theChar = 0; theChar < input.length() -1; theChar ++ ) { - - if (input.charAt(theChar) == 'i' && input.charAt(theChar + 1) == 's') { + if (input.charAt(theChar) == 'i' && input.charAt(theChar + 1) == 's') { // esas letras tiene "is" (la i y s) theIs++; - } - - if (input.charAt(theChar) == 'n' && input.charAt(theChar + 1) == 'o' && + if (input.charAt(theChar) == 'n' && input.charAt(theChar + 1) == 'o' && // estas tiene "not" (n y o y t) input.charAt(theChar + 2) == 't') { theNot++; - } - - } - return theIs.equals(theNot); } @@ -97,18 +103,26 @@ public Boolean containsEqualNumberOfIsAndNot(String input){ */ public Boolean gIsHappy(String input) { + Boolean gIsHappy = false; + for (int i = 0; i < input.length() - 1; i++) { + if (input.charAt(i) == 'g' && input.charAt(i + 1) == 'g') { + gIsHappy = true; + //break; + } + } + return gIsHappy; + } - return input.contains("gg"); -/*int counter = 0; -int gIsHappy = 0; - for (int i = 0; i < in < input.length() -1; i++){ - if (input.charAt(i) == 'g' && input.length() -1 )*/ - + /*return input.contains("gg"); + int counter = 0; + int gIsHappy = 0; + for (int i = 0; i < input.length() -1; i++){ + if (input.charAt(i) == 'g' && input.length() -1 ) + //if (input.charAt(i) == 'g' && input.charAt(i + 1) == 'g') { - //return input.contains("gg"); - } + return input.contains("gg");*/ /** @@ -127,15 +141,14 @@ public Integer countTriple(String input) { 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..b411442 100644 --- a/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java +++ b/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java @@ -26,7 +26,7 @@ public void gIsHappyTest1(){ @Test public void gIsHappyTest2(){ - Boolean actual = stringsAndThings.gIsHappy("xxgxx"); + Boolean actual = stringsAndThings.gIsHappy("gxxgxx"); Assert.assertFalse(actual); } diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class index fd0839f28ef9ac4e8daee21e49801fd5a8432937..e0919c520da5250e0b45460f3f5005d952e882d0 100644 GIT binary patch literal 2249 zcmah~T~pLn7=F$sn=EUnh^%%MD5AE&E@CaBUDQ_bYwH3k6h@rs7?udpC0Tc~e)XoE zp))PE)BXb)z35FZ+8gS4;ScC9=tX~s<5cZ)l5B`AZDA&P&&%_^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