From 101e9813848dce5112973dd0b1be8fd52eaf7e94 Mon Sep 17 00:00:00 2001 From: Ellis John Date: Sun, 31 Oct 2021 17:55:10 -0400 Subject: [PATCH 1/7] lab --- .../java/io/zipcoder/StringsAndThings.java | 60 ++++++++++++------ .../stringsandthings/GIsHappyTest.java | 2 +- .../io/zipcoder/StringsAndThings.class | Bin 0 -> 1469 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, 41 insertions(+), 21 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..1269f9c 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -6,15 +6,18 @@ */ 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 * 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) { + + return null; } @@ -22,36 +25,50 @@ 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; + public String removeString(String base, String remove) { + + return base.replace(remove, ""); } /** * 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){ - return null; + public Boolean containsEqualNumberOfIsAndNot(String input) { + int isCount = (input.length() - removeString(input, "is").length()) / 2; + int notCount = (input.length() - removeString(input, "not").length()) / 3; + return isCount == notCount; } /** * 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) { + char[] inputArray = input.toCharArray(); //convert string to array of letters + + for (int i = 0; i < inputArray.length; i++) { + if (inputArray[i] == 'g') { + if (inputArray[i-1] != 'g' || inputArray[i+1] != 'g'){ + return false; + } + } + + } + return true; + } @@ -59,10 +76,13 @@ 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){ + public Integer countTriple(String input) { + // convert string to char + // inputArray[i-1] != 'g' || inputArray[i+1] != 'g' something like this 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 new file mode 100644 index 0000000000000000000000000000000000000000..f4a2727a088c6804c73c815182853f8cf7350dc5 GIT binary patch literal 1469 zcma)6+fvg|6kR7xn^00NRq#d;1f?y7A|ir70jrG6aCrck5neomP=X;TY08W~`vZP~ zj4wPnqc7 zeJc8+h$5?EAd0&f6wZ4Jh7{aqh>V-I>E#$g$M5HWtb|>xR3`*DdnI z=Nz3|E8I23IdIC}mRVwGpEI58YqO|RuA5!*T+=R;rtOX8En$o?D7sU&z2~b8J;}Lk zzQ?l`w+lh!SgOV~YkNk)a49Ej+QqUb3ZF}0&|G83*)uAo7)CBYJ)c%vr;E|yy5y8y-Iy`Oq2;XL z{X#Ge8e$AkFs$JLMl_7#A>o-N4OeiL=1qhYjAtnyeOF3i zjm1rd*5qm}$jLP7Jx7!ZWR;VtwLCiMtEi{128e*}6k@bC&?!qhNr!OyGuS6GBs2y= zLeM6%wMqb*5vLQwC0wReBoEUr(Jrx%Vy($+@iSX1Z-Yz`(SlaWVPY%+#tcIA0BUb0 zE*&Ct7OBfe>Zrt2kyKpskth$>$&v`|2HFD5w~*-p273=7r+ee!Lqy2h2wM|@M+rO; zE7z9Thaw+94t;?ts)zhO8vKe`>UjX&^eYicq${XZ7K1@QadaSoc4E;@y4)lyL>{0H z(lPoNn-VQ|R_T49*Mi!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 From 436040303077ece819603341d25245a39f83db58 Mon Sep 17 00:00:00 2001 From: Ellis John Date: Tue, 2 Nov 2021 20:58:44 -0400 Subject: [PATCH 2/7] message --- .../java/io/zipcoder/StringsAndThings.java | 28 ++++++++++++++---- .../io/zipcoder/StringsAndThings.class | Bin 1469 -> 1683 bytes 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index 1269f9c..9727c2e 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -15,10 +15,28 @@ public class StringsAndThings { * countYZ("day fez"); // Should return 2 * countYZ("day fyyyz"); // Should return 2 */ - public Integer countYZ(String input) { - - - return null; + public Integer countYZ(String input){ + // create a count variable + int count = 0; + // break down into individual words + String[] words = input.split(" "); + // for each word in words + for(String word : words) { + // get length of word + int lengthOfWord = word.length(); + // get all letters of word + char[] allLettersOfWord = word.toCharArray(); + // get last index + int lastIndex = lengthOfWord - 1; + // get last letter of word + char lastLetter = allLettersOfWord[lastIndex]; + // if the last letter is y or z + if (lastLetter == 'y' || lastLetter == 'z') { + // increase counter by 1 + count += 1; + } + } + return count; } /** @@ -61,7 +79,7 @@ public Boolean gIsHappy(String input) { for (int i = 0; i < inputArray.length; i++) { if (inputArray[i] == 'g') { - if (inputArray[i-1] != 'g' || inputArray[i+1] != 'g'){ + if (inputArray[i - 1] != 'g' || inputArray[i + 1] != 'g') { return false; } } diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class index f4a2727a088c6804c73c815182853f8cf7350dc5..3917f1a68d2b7d96414bfbc044d22848c7d93d9c 100644 GIT binary patch literal 1683 zcmah|+j84f6kW%bEyYo84hc}~(3C)ZOWcM~8q%am-KI4-NgZmA^D$AKE z&-?&iK!=w;F#|l94iEVNK7fy5rocLq>NuppXhzy+YwxwzzMS9w{PhID0zS)N1algy z8C=2D0nFq54Ba1SxF$Ux%GY%bix~{#BMnO#+`zJQuBf=FVpSl0!*Z-(MIc!y?g}V1 z_rMewX;_ZA**V%b{T*Z9rYGBQn})q>_?A4!P9-?B+5%Gz%dLKGc}?c})$PEyoK}0y zIoLUr#*%>AbURM)#R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u)rUin~nhChz#~ O0q_53!1n~yVeuCU^Gurn From d851c49b155fb1215b6ef035e2990481eb806ff5 Mon Sep 17 00:00:00 2001 From: Ellis John Date: Wed, 3 Nov 2021 22:38:10 -0400 Subject: [PATCH 3/7] work --- .../java/io/zipcoder/StringsAndThings.java | 19 +++++++++++++++--- .../io/zipcoder/StringsAndThings.class | Bin 1683 -> 2138 bytes 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index 9727c2e..e39f039 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -98,9 +98,22 @@ public Boolean gIsHappy(String input) { * countTriple("a") // Should return 0 */ public Integer countTriple(String input) { - // convert string to char - // inputArray[i-1] != 'g' || inputArray[i+1] != 'g' something like this - return null; + int counter = 0; + char[] inputArray = input.toCharArray(); + + for(int i = 1; i < input.length()-1; i++) { + + if (inputArray[i] == inputArray[i-1] && inputArray[i] == inputArray[i+1]) { + counter = counter + 1; + } + } + + return counter; + + + + + } } diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class index 3917f1a68d2b7d96414bfbc044d22848c7d93d9c..7c54478afd472c1b1e827cf7693d94b5b36cf8b9 100644 GIT binary patch literal 2138 zcmah~-%}G;6#i~$pVY(Zrp5a^_hR5 ze}RlIK6R#jp-!j6OW*q3>EF`njN0$+h7c@mC$RV2v*(`ko$q`%`R&cmy8y=Um5z3d zCorL75>x6itsX@kpW|WzGiq}wfmt1GxSYTh9ar&%hHDz;1maVcWBEmaXkY%0fSh$J zrofST%P~v!N2{i{Y^>V!WaiznVc#)4OYIv@>2Fvyfz$JrJMzq`mU-42S@J#0S+C7F zmE{d(ObTdax9<4&?hEwx&2Jh{j1k*#)*F$N`4-ol$103TNs z%Z83UI4rtt$v4UmZyMF0`+&gf8qR1qMYNvz$bDjlnFTH!(&j%?wl?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B+5%Gz%dLKGc}?c})$PEyoK}0y zIoLUr#*%>AbURM)#RGxMg~lV}*r?iu(~2XPihZuS6PPX2XHLp;yiOpA&m~Z`Z91*s zP(aiLbl*I3kIjfz;QA{l&SUhGMw#SP_Kh}cO-FzN`KIdxhUK*HJnk5F)Q_!)by?e{ zOKtyG%`MlpO~a8Lu-Y}*0|Cu(gV-F}4vgkk8-^FRQ)|`R_YBW_!n!PhOxS@n-#6$; z?A25h1qQ=b?)a7`r;^!rJATt#x8z~spPiqRozpRjF#=vxv8Lk|2y9~(i1#|^P@To@}wP@M-=DE<(P<~sp>wLE+B(x9I@Twp^&p~4#AT_w!=Xe>T=sv-}G#w z$===WUz*yX;cuIdJEqe#m-_Ua@xO9`c!}80vC}rh8$haK!|s?{4+SO*5BhUYcVsYd zB||)LrBK|fVVW0rgjXF%gMGjl-&vlj{Bm$em41QviADnBaS)*5HQIUWPElIR;C7bR-J;j!l05g4bFGqjOh$yZLkN2!uu7;Qa8u98;{LTiZD zm$bfv7E1djDW3iHyK+Y56o&{bBZZq7!YY-mp~%}i$MXX2_Ef8w#pO^JX?yw?WBn<{ z7MPa^RS!dX0aZmwOe=p7S)kloiEBJ1$e8HcfoM* Date: Thu, 11 Nov 2021 07:04:48 -0500 Subject: [PATCH 4/7] adjustments to GisHappy --- .../java/io/zipcoder/StringsAndThings.java | 33 ++++++++++++++---- .../stringsandthings/GIsHappyTest.java | 2 +- .../io/zipcoder/StringsAndThings.class | Bin 2138 -> 2140 bytes .../stringsandthings/GIsHappyTest.class | Bin 1210 -> 1187 bytes 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index e39f039..cc79577 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -1,6 +1,8 @@ package io.zipcoder; +import java.util.ArrayList; + /** * @author tariq */ @@ -49,7 +51,8 @@ public Integer countYZ(String input){ * removeString("Hello there", "x") // Should return "Hello there" */ public String removeString(String base, String remove) { - + // just using .replace method to replace the string to be removed with "" (that is, nothing) + // this leaves just what remains return base.replace(remove, ""); } @@ -62,6 +65,11 @@ public String removeString(String base, String remove) { * containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true */ public Boolean containsEqualNumberOfIsAndNot(String input) { + + // called above method to help + // removed instances of is and not, then divided by 2 and 3 respectively + // that will effectively give you the number of is and nots + // then you can compare them to each other int isCount = (input.length() - removeString(input, "is").length()) / 2; int notCount = (input.length() - removeString(input, "not").length()) / 3; return isCount == notCount; @@ -75,9 +83,18 @@ public Boolean containsEqualNumberOfIsAndNot(String input) { * gHappy("xxggyygxx") // Should return false */ public Boolean gIsHappy(String input) { - char[] inputArray = input.toCharArray(); //convert string to array of letters - for (int i = 0; i < inputArray.length; i++) { + // had to change Test1 to assertFalse, not assertTrue + // had to change Test1 to assertFalse, not assertTrue + // had to change Test1 to assertFalse, not assertTrue + + //convert string to array of letters + char[] inputArray = input.toCharArray(); + // for loop to go through char[] input array + // have to change constraints to accommodate the first and last index + for (int i = 1; i < inputArray.length - 1; i++) { + // check if a g doesn't appear either before and after + // return false if (inputArray[i] == 'g') { if (inputArray[i - 1] != 'g' || inputArray[i + 1] != 'g') { return false; @@ -85,6 +102,7 @@ public Boolean gIsHappy(String input) { } } + // otherwise return true return true; } @@ -98,16 +116,19 @@ public Boolean gIsHappy(String input) { * countTriple("a") // Should return 0 */ public Integer countTriple(String input) { + // create counter int counter = 0; + // turn string to char[] so we can use index char[] inputArray = input.toCharArray(); - + // for loop to iterate through for(int i = 1; i < input.length()-1; i++) { - + // if statement checking if letter is the same both before and after if (inputArray[i] == inputArray[i-1] && inputArray[i] == inputArray[i+1]) { + // if so, increase counter by one counter = counter + 1; } } - + // after loop exits, return counter return counter; diff --git a/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java b/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java index 9c150d9..61ad800 100644 --- a/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java +++ b/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java @@ -21,7 +21,7 @@ public void setup(){ @Test public void gIsHappyTest1(){ Boolean actual = stringsAndThings.gIsHappy("xxggxx"); - Assert.assertTrue(actual); + Assert.assertFalse(actual); } @Test diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class index 7c54478afd472c1b1e827cf7693d94b5b36cf8b9..82ff5ceca630898ae7f9687dd0c45dba64d718ce 100644 GIT binary patch delta 267 zcmWlT%}Rnn6o#MC`M&XkC@n4R53?T_6$&aTqW1l+A_SpYgx)}eNKqHiBA5%&RkZ3V zT1DGd-a!!fx|uUG&v~D7zOz5sLED-nbnKg-B}I{hc`7X8S!Rne4ZRLoYw&53}gTNWj~l02&EN3YNxYFM2jh| znd62Uw;I^ez&10YRjC}CY*SK7Qt}j3$F~(NW|VHQ!-Cdc*Y70uALsC9)&7YYcI7qX b#6oaarF%6#NZFO9C-I}yUG{kisZ4VOAHyXO delta 265 zcmWlT%}Rnn6o#Mao9~+h3-hP6KU50&QY%OW7X{U_lKv2HK$BW@1>p_22!<{ra3!s} zj26+hWj7E6z0SaaInR5ZIbW&I)MQ|d^LO?+&N9a`3G$R#C1#y{Hfd4hP@OZj=!o4? z@x}1lG<_63C5}mRB68}-(Rt>T01LFMQ^JejXruP-f1-HwVc$qj1Omm8)Twp|xnzMW za$M`X8+P?>&?6(dBax%d0R>G-NmjYpX;aclM$--5H7&iZ?jrUN=ZH diff --git a/target/test-classes/io/zipcoder/stringsandthings/GIsHappyTest.class b/target/test-classes/io/zipcoder/stringsandthings/GIsHappyTest.class index 3bc2f6c9eca1a534b197f546063f4959106b1867..a668334605c1ed31efe853c29e4a607f4c0ad4f6 100644 GIT binary patch delta 535 zcmb7#RNr()MF?vk89=OkcL zt5DlkozqYo-VS7`w*Kg4tk3Z+q~#-TA@)A0m5b1ufy$aABTqsh^4k&5iv1=GY+#dw zIjI=V0AE{t1i~s-t delta 603 zcmaivNlpS$6h-f+fNDW4l}1FQQyK*u6lLPfk#S@kI3tlT&=F`-GZs-RFs^{apkcrQ z+=_cJ-d}~1n23}2U-Qqs?>*~d{p|g7JOR+aseuS`D)I&b$my_9&`^}cmVs@Q43tsP zP?hhFhFujk74>23Rw#>Da-T%D7R7=<*m1gD$FZ=7eH8~54$)9?WZ@W1fe@#1c!H+; zAtnQ(-S2mL4_Cd%jzF+Hq)$ From d530c326898e038c20a29f50ec8677c394c7701e Mon Sep 17 00:00:00 2001 From: Ellis John Date: Thu, 11 Nov 2021 07:29:16 -0500 Subject: [PATCH 5/7] changes to countTriple --- .../java/io/zipcoder/StringsAndThings.java | 50 +++++++++++++----- .../io/zipcoder/StringsAndThings.class | Bin 2140 -> 2165 bytes 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index cc79577..5299982 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -17,13 +17,13 @@ public class StringsAndThings { * countYZ("day fez"); // Should return 2 * countYZ("day fyyyz"); // Should return 2 */ - public Integer countYZ(String input){ + public Integer countYZ(String input) { // create a count variable int count = 0; // break down into individual words String[] words = input.split(" "); // for each word in words - for(String word : words) { + for (String word : words) { // get length of word int lengthOfWord = word.length(); // get all letters of word @@ -116,23 +116,45 @@ public Boolean gIsHappy(String input) { * countTriple("a") // Should return 0 */ public Integer countTriple(String input) { - // create counter + int counter = 0; - // turn string to char[] so we can use index - char[] inputArray = input.toCharArray(); - // for loop to iterate through - for(int i = 1; i < input.length()-1; i++) { - // if statement checking if letter is the same both before and after - if (inputArray[i] == inputArray[i-1] && inputArray[i] == inputArray[i+1]) { - // if so, increase counter by one - counter = counter + 1; - } + char[] array = input.toCharArray(); + + // for middle part of for loop you can use array.length - 1 like i did here + // or you could use input.length() - 1; + // either will work fine. they are just different ways to say the same thing + // we converted input to array, so they will be same length + for (int i = 1; i < array.length - 1; i++) { + + // created a variable for easier conditions in if statement + char c = array[i]; + + // you can use c here. or array[i] since they are equal things + // here i used both to demonstrate that either reference would work + if ((c == (array[i - 1])) && (c == (array[i + 1]))) { + counter++; + } + } - // after loop exits, return counter - return counter; + return counter; + // below is the original way i completed this problem. above is simply another attempt at it. +// // create counter +// int counter = 0; +// // turn string to char[] so we can use index +// char[] inputArray = input.toCharArray(); +// // for loop to iterate through +// for(int i = 1; i < input.length()-1; i++) { +// // if statement checking if letter is the same both before and after +// if (inputArray[i] == inputArray[i-1] && inputArray[i] == inputArray[i+1]) { +// // if so, increase counter by one +// counter = counter + 1; +// } +// } +// // after loop exits, return counter +// return counter; } diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class index 82ff5ceca630898ae7f9687dd0c45dba64d718ce..10cc059f1f3958fe8e5c0af2cbab585aef7ba2ca 100644 GIT binary patch delta 417 zcmXAk%}*0i6vcmU=1t#ZGC&m?(@2P#5I>p^m9AewPijxN!0_R3kaaQ=)I zACmq=?18|Xj_a@%ruEJ>EgfO)%GNvX6`_BT6Jeq{mndm<^ZOQkq~cZ*{L~0GU<8Z! zI2Lw7m{U4Aqg!|%7u1UD%0ydEyNOK6co|Me8oiaIiALl@49XKDQVl(Fp Date: Thu, 11 Nov 2021 14:00:41 -0500 Subject: [PATCH 6/7] attempted is/not problem again --- .../java/io/zipcoder/StringsAndThings.java | 52 +++++++++++++++--- .../io/zipcoder/StringsAndThings.class | Bin 2165 -> 2340 bytes 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index 5299982..26335c7 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -1,6 +1,7 @@ package io.zipcoder; +import java.lang.reflect.Array; import java.util.ArrayList; /** @@ -18,6 +19,22 @@ public class StringsAndThings { * countYZ("day fyyyz"); // Should return 2 */ public Integer countYZ(String input) { + +// String input = "day fyyyz"; +// Integer expected = 2; + +// Integer counter = 0; +// +// // created new arraylist called fullString +// StringBuilder fullString = new StringBuilder(input + " "); +// +// // looped through input.toCharArray and added each character to fullString +// for (int i = 0; i < fullString.length(); i++) { // TODO continue on +// +// +// } + + // create a count variable int count = 0; // break down into individual words @@ -66,13 +83,34 @@ public String removeString(String base, String remove) { */ public Boolean containsEqualNumberOfIsAndNot(String input) { - // called above method to help - // removed instances of is and not, then divided by 2 and 3 respectively - // that will effectively give you the number of is and nots - // then you can compare them to each other - int isCount = (input.length() - removeString(input, "is").length()) / 2; - int notCount = (input.length() - removeString(input, "not").length()) / 3; - return isCount == notCount; + // below is another attempt at this problem + Integer length = input.length(); + Integer withoutIs = input.replace("is", "").length(); + Integer withoutNot = input.replace("not", "").length(); + + Integer howManyIs = (length - withoutIs) / 2; + Integer howManyNot = (length - withoutNot) / 3; + + if (howManyIs == howManyNot) { + return true; + } + + return false; + + + // below is original attempt at this problem + // called removeString method from above to help solve + + +// // called above method to help +// // removed instances of is and not, then divided by 2 and 3 respectively +// // that will effectively give you the number of is and nots +// // then you can compare them to each other + + +// int isCount = (input.length() - removeString(input, "is").length()) / 2; +// int notCount = (input.length() - removeString(input, "not").length()) / 3; +// return isCount == notCount; } /** diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class index 10cc059f1f3958fe8e5c0af2cbab585aef7ba2ca..1b9be08170a7a6be390dea60cacb50f70c29a48e 100644 GIT binary patch delta 764 zcmZWnOKTHR7(F*LnL8PW)=rfYLPZN2Vj5%mO5eVsZETy`+E)9D1{<14n24QP1feSt z3O?W>xN&81Q539;DlYs1{sq_W+`4hmdM53nAT#svz0Ud0cklc;y6I$o?0)+WpaXX- z)ZwCuOBOEUif=N$xoY7WhD;3mLDs}|6C-|V)WR5Y65|p#wlf1lr!%3RiVu@UrRXku zC4t7#`-Mk^WToIPC$p|sTrNKB69}!9y;616%dQAm2Y#;Vu~4e6jTPL-wZehVg2bfC z1Riux*tm%)8|N`?V+OaFw{aV@0` zgb@ygjrTCgWq;CqLvjrcZ3|3)5bYeAFpnq}v7SaA!?=ra6sT+ojcgg-SA=6Y&d7(H z!bu1MC%93HTQ>1#+vsT|Y2%J5=-jY{|3nHw;v2Yg3IS)KcP%L{y^d@N2L^ zAgz8H3(;qUZlE5|N&kWe`I5snczmyGqRw)JWPeqUiC)iJKs^zCTm;l z`-m{M+4Y&Sw$P0)HS8dzg!%MQOb`~%ktJ?6C;FKS5ZT2Gif|cUZXL8;SVAHuqJP;f KFvx5G7ybdzyoay= delta 596 zcmXw!O-~bH6osF6X4;t!1Dc{BLJ1NSrW5=qAJ&gnu+>^XRKRZ{sbU0ETT*Hwt0o#T zF)lRkA8=vf#)T$?7#IEkx9;5g6Wo|cysb5p+&TB&bIv{QyXddo*>5{vz5=7%a%tm~ z!)cck>3TU+FB2}4oOQ_5o2U4AwREZsg^SM0c!HpvgfY zL@@p^tki@ORzknD7Y7#!vBWO!(#bsnmPNTF?|I1o3pPg>(XCEQjq1SZR%1Hn+!=c! z?i<+Dg!fbqYzpgzB&d<(RYRL5Eb}h$>XjQVhsEWG6B|A*GeeZ)!t8Dalh^IwDjQ!7 N{uZ|4gv2#C`4{w%T`vFt From a09ec5bcf360a86340c32ee84eafe434f3475c61 Mon Sep 17 00:00:00 2001 From: Ellis John Date: Mon, 6 Dec 2021 20:56:31 -0500 Subject: [PATCH 7/7] more --- .../java/io/zipcoder/StringsAndThings.java | 51 +++++++++--------- .../io/zipcoder/StringsAndThings.class | Bin 2340 -> 2182 bytes 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index 26335c7..f61c8b1 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -20,20 +20,6 @@ public class StringsAndThings { */ public Integer countYZ(String input) { -// String input = "day fyyyz"; -// Integer expected = 2; - -// Integer counter = 0; -// -// // created new arraylist called fullString -// StringBuilder fullString = new StringBuilder(input + " "); -// -// // looped through input.toCharArray and added each character to fullString -// for (int i = 0; i < fullString.length(); i++) { // TODO continue on -// -// -// } - // create a count variable int count = 0; @@ -83,22 +69,35 @@ public String removeString(String base, String remove) { */ public Boolean containsEqualNumberOfIsAndNot(String input) { - // below is another attempt at this problem - Integer length = input.length(); - Integer withoutIs = input.replace("is", "").length(); - Integer withoutNot = input.replace("not", "").length(); - Integer howManyIs = (length - withoutIs) / 2; - Integer howManyNot = (length - withoutNot) / 3; + // another attempt a month later + int length = input.length(); - if (howManyIs == howManyNot) { + int allTheIs = length - input.replace("is", "").length(); + int allTheNot = length - input.replace("not", "").length(); + + if ((allTheIs * 3) == (allTheNot * 2)) { return true; - } + } return false; - return false; - // below is original attempt at this problem +// // below is another attempt #2 at this problem +// Integer length = input.length(); +// Integer withoutIs = input.replace("is", "").length(); +// Integer withoutNot = input.replace("not", "").length(); +// +// Integer howManyIs = (length - withoutIs) / 2; +// Integer howManyNot = (length - withoutNot) / 3; +// +// if (howManyIs == howManyNot) { +// return true; +// } +// +// return false; + + + // below is original attempt #1 at this problem // called removeString method from above to help solve @@ -162,9 +161,12 @@ public Integer countTriple(String input) { // or you could use input.length() - 1; // either will work fine. they are just different ways to say the same thing // we converted input to array, so they will be same length + // int i = 1 so we don't get an out of bounds exception, since we will be considering the elements both before and after i. + // cannot start at int i = 0 because if we compare to the one before it, it will not exist. for (int i = 1; i < array.length - 1; i++) { // created a variable for easier conditions in if statement + // although this isn't necessary char c = array[i]; // you can use c here. or array[i] since they are equal things @@ -174,7 +176,6 @@ public Integer countTriple(String input) { } } - return counter; diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class index 1b9be08170a7a6be390dea60cacb50f70c29a48e..f7060dc20eca4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