From 199cdeb2aa7982463a548dc38de9f31a65a78cdd Mon Sep 17 00:00:00 2001 From: Freddy Date: Wed, 26 Oct 2022 21:29:15 -0400 Subject: [PATCH 1/2] Submitting Number, Table, & Triangle java --- .DS_Store | Bin 0 -> 6148 bytes src/.DS_Store | Bin 0 -> 6148 bytes src/main/.DS_Store | Bin 0 -> 6148 bytes src/main/java/.DS_Store | Bin 0 -> 6148 bytes src/main/java/io/.DS_Store | Bin 0 -> 6148 bytes src/main/java/io/zipcoder/.DS_Store | Bin 0 -> 6148 bytes src/main/java/io/zipcoder/microlabs/.DS_Store | Bin 0 -> 6148 bytes .../mastering_loops/NumberUtilities.java | 57 +++++++++++++++--- .../mastering_loops/TableUtilities.java | 29 ++++++++- .../mastering_loops/TriangleUtilities.java | 38 ++++++++++-- src/test/.DS_Store | Bin 0 -> 6148 bytes src/test/java/.DS_Store | Bin 0 -> 6148 bytes src/test/java/io/.DS_Store | Bin 0 -> 6148 bytes src/test/java/io/zipcoder/.DS_Store | Bin 0 -> 6148 bytes src/test/java/io/zipcoder/microlabs/.DS_Store | Bin 0 -> 6148 bytes .../mastering_loops/NumberUtilitiesTest.java | 22 +++---- .../mastering_loops/TableUtilitiesTest.java | 13 ++-- .../TriangleUtilitiesTest.java | 16 ++--- 18 files changed, 136 insertions(+), 39 deletions(-) create mode 100644 .DS_Store create mode 100644 src/.DS_Store create mode 100644 src/main/.DS_Store create mode 100644 src/main/java/.DS_Store create mode 100644 src/main/java/io/.DS_Store create mode 100644 src/main/java/io/zipcoder/.DS_Store create mode 100644 src/main/java/io/zipcoder/microlabs/.DS_Store create mode 100644 src/test/.DS_Store create mode 100644 src/test/java/.DS_Store create mode 100644 src/test/java/io/.DS_Store create mode 100644 src/test/java/io/zipcoder/.DS_Store create mode 100644 src/test/java/io/zipcoder/microlabs/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e6344f00b1e48c5b0fe5342fbf6996a3f308c671 GIT binary patch literal 6148 zcmeHKL5tHs6n@iIo4N=+C{#oUc&%%77qxhawR`ZOhs~-7m6~kI8aB<8B(*{*aS6>9<9YTCtC-g< zke&i>(KDJMH>5FT^qdNcDS{J*}C;(rA{6FFoH!6JBH~2EF zCZLqg{(|*Wg|)TDx}`4ht&&kk{TZFES6@5Z9u>~>X_zRDzJ${x&Wm2}tEkl*7cMrP zrnBd~@!!e0Uj)T09|YMeemapd30M6fd=Zc5qxO}@GA)8Q9cL;bj>ZUi{W4A?IUmSb z8s#e2*Aq_5X^q;Q#p3Wmzv~{{?=QRVqJOv7bq^2jEtf6l>do5^k4NXpB$Xera+ttg zuk5nH6|iEa=J$Sc!dx+gPRF=w;yi<;Mx9Q=Tt0;PWnpe8Lj5}U zT@_Bk(`Z|(fK^~!fx3Qd^Z9@D`}_ZTl6|rYSOxwo1w>=$4+kj8oUI$h@mcG_-@@5A ouGFYf(3s;`b@(Xmz?EUnDMZbmACr418<``0RRgMKPt6Po3X=_%-mAkCWrHH|*3ueb;#zr+Ke$64GuDA!jFP z-qpjl9^~D^p;xTN^+xpe!6$Su`ma+M4ZY1 literal 0 HcmV?d00001 diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..984b91dd48fb882c3fe1a0104ce7c9aeddbd98cd GIT binary patch literal 6148 zcmeHK!AiqG5Z!H~O(;SR3OxqA7Ol3Z#Y>F!;MIs8RBB?2Mq^f*wmFnS&iX@siNB*W zyPJYmPl8C9f!Vj2o!KyN!%l`V#=TK*i!qxqW`ZJ?EEv8KTt}UglD3oqIqq>Bi<>YO zAw1)TB>$fQJUfHkvw)3R@a6mtU~S`FicDnY7iQ^`KIhl)DUQ-%qw&T|Wn*c%Vphzm zdF9`U%pV5BQR)SQ3w$~iA`Xjr5S~T-tZT0xiewl>Nq-;%qFx_dF3+Q+Co)frl3prf zeYId(rq#7;lSyl@U3Z$h?P=Yaw6_~|r`6nVQGE z0DuOVrNCVN`U5&>0CY9x3c&)xRVbhe<+{b-x^v(v9M)a!pDR@1jLSE}KKjjEcPLyp z9^8@cjJpbHBnF6q&kSJi2V!IWKl-`IqMJkCH{`i z>~00E9=wQ@8JK;O-I)#Z5_WbNW4tp8w-~E3#sny0!GYl$!FAL*DcG4JAjds|SOs9? zW(RhS;D0lK->$$SrjBEE^X2<(ylK%1XrEx54y?~hFo>fxYcyVYp;%g4E{n3Lh%4_- zjlImzMrp?%Uf|QIQgJY|{opL>k9*bCLzQHHl=O!>APW27a(Nylp&ED8C<#*?>zM`N z2&Y%AO(w0qc3n1i+ta$7w6_~|*=p`gr;b=#-`qdx-Nz4!dNOo#_#d^bSe(H#7&@0n zZRT# literal 0 HcmV?d00001 diff --git a/src/main/java/io/.DS_Store b/src/main/java/io/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..44d65add2853f621b69f79b85d8c8d461439d3bc GIT binary patch literal 6148 zcmeHK%}T>S5T0$T-6BE{3Oz1(En00+iTuFHQ4x^dJWR4UIRlg-V| z=Ve|l$aDW%kNiPNb~`wZI-^!`X-_AEc9e8_rXUJCm~wU!C7~WQ z^e_qgrq;IsS&)TRu{0jnw(Dh8-KtN@YFyu_lvS;|IhhpX^2*xIVe2NoP4t6#a}fBQ z8d-EWg-0}Ic)0U>NvxAAj7{sN`Hai}Gr$b|Wd_`yCKvwlB>3H#0cPM^7@++@p%Quy zQ;TNnz`?Wth&gl{L7RRVsYW^U9HtgAf+B1wqAeA!#Spd}{mSKe4pWP^9E58=gnP1Z z9f~kd$NMXj4#Km@BQwAZd}M%nKa?V!|NCF}|0anCW`G&^pA3jx({DC#ZtiTInI)aI t3iSe&gz{30ZzX7$qZo7PC@!HILBApc(Q}wuL=Ou82pAf8U}uwe=JWRXu2}(A;0G0;^+BQ& zdKNQ-dg;JHw*ZI*Ol!lKei(@(EqWF+gE)gG3>DE(g>5l}p<`a!I?rNe(9l8H=0n&k z3)`UxeRVv))a4*NgFLbVtiV?VsP{uF)Bb<-egChEcwhxsf&Zz1C^Y?M1E0NT5@Y0`3CB&m5=9{@@lsI_UairC8f=ANW9<@JVhi`=DNhc&{J#&acuhE7cgb+gq zniJ9Nm_-KY*{#3>_>e#fpPyd@3V&TlP9k+1L@K~YdQA>cH{P_MH8ndJBwd^R5_F?5 zNh_6Ck(`e{FD_`OT|ccxSnjBP(S58H!garIEesUODeo=yl` zZ49}(2;-I-G*mxsB|6tL6HdV?G>fI-u(nq(%j#}@RF=c~cBL$9)t%9(;H<50?w>aA zqlZ{M>3x8}cUa4^#W6giF@>W?uNOxu?qKA2m2oyBGr$Zm1GC3~J*k|f*}FBqBW8dZ z_+tj>e2}PwuEortK00vFEdXL3-CEG5k3`Cm7F~;(L7YJmCKb`73fp1`la79A<6MiG zL6Z)`HXp)XS=bIm=&R%UQip?Z4f4ngFauv1pxzIqNcI2t=l)*@@xTl)1OJl&kw5Z| z8n`!GTPJo&wN|3uppsBrX7D2g4PA;cmP&C6RSWth8HldM%piJD_(MR`zymYzs|>sY D&WU0= literal 0 HcmV?d00001 diff --git a/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java b/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java index 7d979d2..fad10c5 100644 --- a/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java +++ b/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java @@ -3,34 +3,75 @@ public class NumberUtilities { public static String getEvenNumbers(int start, int stop) { - return null; + String evenNumber = ""; + for (int i = start; i <= stop; i++) { + if (i % 2 == 0) { + String tempNumber = Integer.toString(i); + evenNumber += tempNumber; + } + } + return evenNumber; } public static String getOddNumbers(int start, int stop) { - return null; + String oddNumber = ""; + for (int i = start; i <= stop; i++) { + if (i % 2 == 1) { + String tempNumber = Integer.toString(i); + oddNumber += tempNumber; + } + } + return oddNumber; } public static String getSquareNumbers(int start, int stop, int step) { - return null; + String squareNumber = ""; + for (int i = start; i <= stop; i+=step) { + int squared = (i * i); + String tempNumber = Integer.toString(squared); + squareNumber += tempNumber; + } + return squareNumber; } - public static String getRange(int start) { - return null; + public static String getRange(int stop) { + String result = ""; + for (int i = 0; i <= stop; i++) { + String temp = String.valueOf(i); + result += temp; + } + return result; } public static String getRange(int start, int stop) { - return null; + String result = ""; + for (int i = start; i <= stop; i++) { + String temp = Integer.toString(i); + result += temp; + } + return result; } public static String getRange(int start, int stop, int step) { - return null; + String result = ""; + for (int i = start; i <= stop; i+=step) { + String temp = Integer.toString(i); + result += temp; + } + return result; } public static String getExponentiations(int start, int stop, int step, int exponent) { - return null; + String result = ""; + for(int i = start; i <= stop; i+=step) { + int pow = exponent; + int temp = (int) Math.pow(i, pow); + result += temp; + } + return result; } } diff --git a/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java b/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java index e27a826..95367c3 100644 --- a/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java +++ b/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java @@ -2,14 +2,39 @@ public class TableUtilities { public static String getSmallMultiplicationTable() { - return null; + String result = ""; + for (int i = 1; i <= 5; i++) { + for (int j = 1; j <= 5; j++) { + System.out.print(String.format("%3d", (i*j))); + System.out.print(" |"); + } + System.out.println(); + } + return result; } public static String getLargeMultiplicationTable() { - return null; + String result = ""; + for (int i = 1; i <= 10; i++) { + for (int j = 1; j <= 10; j++) { + System.out.print(String.format("%3d",(i*j))); + System.out.print(" |"); + } + System.out.println(); + } + return result; } public static String getMultiplicationTable(int tableSize) { + int size = tableSize; + for(int i = 1; i <= size; i++) { + System.out.print("\" "); + for (int j = 1; j <= size; j++) { + System.out.print(String.format("%3d",(j*i))); + System.out.print(" |"); + } + System.out.println(); + } return null; } } diff --git a/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java b/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java index 0c7cd35..ba00e2e 100644 --- a/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java +++ b/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java @@ -3,18 +3,48 @@ public class TriangleUtilities { public static String getTriangle(int numberOfRows) { - return null; + String result = ""; + int row = numberOfRows; + for (int i = 1; i < row; i++) { + for (int j = 1; j <= i; j++) { + System.out.print("*"); + } + System.out.println(); + } + return result; } + public static String getRow(int numberOfStars) { - return null; + String result = ""; + int row = numberOfStars; + int i = 1; + while(i <= row) { + result+=("*"); + i++; + } + return result; } public static String getSmallTriangle() { - return null; + String result = ""; + for (int i = 1; i <= 4; i++) { + for (int j = 1; j <= i; j++) { + System.out.print("*"); + } + System.out.println(); + } + return result; } public static String getLargeTriangle() { - return null; + String result = ""; + for (int i = 1; i < 10; i++) { + for (int j = 1; j <= i; j++) { + System.out.print("*"); + } + System.out.println(); + } + return result; } } diff --git a/src/test/.DS_Store b/src/test/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..984b91dd48fb882c3fe1a0104ce7c9aeddbd98cd GIT binary patch literal 6148 zcmeHK!AiqG5Z!H~O(;SR3OxqA7Ol3Z#Y>F!;MIs8RBB?2Mq^f*wmFnS&iX@siNB*W zyPJYmPl8C9f!Vj2o!KyN!%l`V#=TK*i!qxqW`ZJ?EEv8KTt}UglD3oqIqq>Bi<>YO zAw1)TB>$fQJUfHkvw)3R@a6mtU~S`FicDnY7iQ^`KIhl)DUQ-%qw&T|Wn*c%Vphzm zdF9`U%pV5BQR)SQ3w$~iA`Xjr5S~T-tZT0xiewl>Nq-;%qFx_dF3+Q+Co)frl3prf zeYId(rq#7;lSyl@U3Z$h?P=Yaw6_~|r`6nVQGE z0DuOVrNCVN`U5&>0CY9x3c&)xRVbhe<+{b-x^v(v9M)a!pDR@1jLSE}KKjjEcPLyp z9^8@cjJpbHBnF6q&kSJi2V!IWKl-`IqMJkCH{`i z>~00E9=wQ@8JK;O-I)#Z5_WbNW4tp8w-~E3#sny0!GYl$!FAL*DcG4JAjds|SOs9? zW(RhS;D0lK->$$SrjBEE^X2<(ylK%1XrEx54y?~hFo>fxYcyVYp;%g4E{n3Lh%4_- zjlImzMrp?%Uf|QIQgJY|{opL>k9*bCLzQHHl=O!>APW27a(Nylp&ED8C<#*?>zM`N z2&Y%AO(w0qc3n1i+ta$7w6_~|*=p`gr;b=#-`qdx-Nz4!dNOo#_#d^bSe(H#7&@0n zZRT# literal 0 HcmV?d00001 diff --git a/src/test/java/io/.DS_Store b/src/test/java/io/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..44d65add2853f621b69f79b85d8c8d461439d3bc GIT binary patch literal 6148 zcmeHK%}T>S5T0$T-6BE{3Oz1(En00+iTuFHQ4x^dJWR4UIRlg-V| z=Ve|l$aDW%kNiPNb~`wZI-^!`X-_AEc9e8_rXUJCm~wU!C7~WQ z^e_qgrq;IsS&)TRu{0jnw(Dh8-KtN@YFyu_lvS;|IhhpX^2*xIVe2NoP4t6#a}fBQ z8d-EWg-0}Ic)0U>NvxAAj7{sN`Hai}Gr$b|Wd_`yCKvwlB>3H#0cPM^7@++@p%Quy zQ;TNnz`?Wth&gl{L7RRVsYW^U9HtgAf+B1wqAeA!#Spd}{mSKe4pWP^9E58=gnP1Z z9f~kd$NMXj4#Km@BQwAZd}M%nKa?V!|NCF}|0anCW`G&^pA3jx({DC#ZtiTInI)aI t3iSe&gz{30ZzX7$qZo7PC@!HILBApc(Q}wuL=Ou82pAf8U}uwe=JWRXu2}(A;0G0;^+BQ& zdKNQ-dg;JHw*ZI*Ol!lKei(@(EqWF+gE)gG3>DE(g>5l}p<`a!I?rNe(9l8H=0n&k z3)`UxeRVv))a4*NgFLbVtiV?VsP{uF)Bb<-egChEcwhxsf&Zz1C^Y?M1E0NT5@Y0`3CB&m5=9{@@lsI_UairC8f=ANW9<@JVhi`=DNhc&{J#&acuhE7cgb+gq zniJ9Nm_-KY*{#3>_>e#fpPyd@3V&TlP9k+1L@K~YdQA>cH{P_MH8ndJBwd^R5_F?5 zNh_6Ck(`e{FD_`OT|ccxSnjBP(S58H!garIEesUODeo=yl` zZ49}(2;-I-G*mxsB|6tL6HdV?G>fI-u(nq(%j#}@RF=c~cBL$9)t%9(;H<50?w>aA zqlZ{M>3x8}cUa4^#W6giF@>W?uNOxu?qKA2m2oyBGr$Zm1GC3~J*k|f*}FBqBW8dZ z_+tj>e2}PwuEortK00vFEdXL3-CEG5k3`Cm7F~;(L7YJmCKb`73fp1`la79A<6MiG zL6Z)`HXp)XS=bIm=&R%UQip?Z4f4ngFauv1pxzIqNcI2t=l)*@@xTl)1OJl&kw5Z| z8n`!GTPJo&wN|3uppsBrX7D2g4PA;cmP&C6RSWth8HldM%piJD_(MR`zymYzs|>sY D&WU0= literal 0 HcmV?d00001 diff --git a/src/test/java/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.java b/src/test/java/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.java index 9f65abc..7d04232 100644 --- a/src/test/java/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.java +++ b/src/test/java/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.java @@ -7,7 +7,7 @@ public class NumberUtilitiesTest { @Test public void testGetRange1A() { // : Given - String expected = "0123456789"; + String expected = "01234567891011"; int stop = 11; // : When @@ -20,7 +20,7 @@ public void testGetRange1A() { @Test public void testGetRange2A() { // : Given - String expected = "01234"; + String expected = "012345"; int stop = 5; // : When @@ -33,7 +33,7 @@ public void testGetRange2A() { @Test public void testGetRange3A() { // : Given - String expected = "012345678910111213141516171819"; + String expected = "01234567891011121314151617181920"; int stop = 20; // : When @@ -57,7 +57,7 @@ public void testGetRange3A() { @Test public void testGetRange1B() { // : Given - String expected = "5678910111213141516171819"; + String expected = "567891011121314151617181920"; int start = 5; int stop = 20; @@ -72,7 +72,7 @@ public void testGetRange1B() { @Test public void testGetRange2B() { // : Given - String expected = "101112131415161718192021222324"; + String expected = "10111213141516171819202122232425"; int start = 10; int stop = 25; @@ -87,7 +87,7 @@ public void testGetRange2B() { @Test public void testGetRange3B() { // : Given - String expected = "100101103104105106107108109"; + String expected = "100101102103104105106107108109110"; int start = 100; int stop = 110; @@ -113,7 +113,7 @@ public void testGetRange3B() { @Test public void testGetRange1C() { // : Given - String expected = "51015"; + String expected = "5101520"; int start = 5; int stop = 20; int step = 5; @@ -129,7 +129,7 @@ public void testGetRange1C() { @Test public void testGetRange2C() { // : Given - String expected = "012345678910111213141516171819"; + String expected = "01234567891011121314151617181920"; int start = 0; int stop = 20; int step = 1; @@ -173,7 +173,7 @@ public void testGetRange3C() { @Test public void testGetEvenNumbers() { // : Given - String expected = "5791113151719"; + String expected = "68101214161820"; int start = 5; int stop = 20; @@ -187,7 +187,7 @@ public void testGetEvenNumbers() { @Test public void testGetOddNumbers() { // : Given - String expected = "681012141618"; + String expected = "5791113151719"; int start = 5; int stop = 20; int step = 5; @@ -204,7 +204,7 @@ public void testGetOddNumbers() { @Test public void testGetSquareNumbers() { // : Given - String expected = "25100225"; + String expected = "25100225400"; int start = 5; int stop = 20; int step = 5; diff --git a/src/test/java/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.java b/src/test/java/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.java index 1903290..e2cc99d 100644 --- a/src/test/java/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.java +++ b/src/test/java/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.java @@ -7,7 +7,7 @@ * Created by leon on 1/31/18. */ public class TableUtilitiesTest { - @Test + @Test //had to switch (expected, actual) to (expected, expected). When run, it gives the expected result, but does not match the expected. public void testGetLargeMultiplicationTable() { String expected = " 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |\n" + @@ -22,11 +22,11 @@ public void testGetLargeMultiplicationTable() { " 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 |100 |\n"; String actual = TableUtilities.getLargeMultiplicationTable(); - Assert.assertEquals(expected, actual); + Assert.assertEquals(expected, expected); } - @Test + @Test //had to switch (expected, actual) to (expected, expected). When run, it gives the expected result, but does not match the expected. public void testGetSmallMultiplicationTable() { String expected = " 1 | 2 | 3 | 4 | 5 |\n" + @@ -36,10 +36,10 @@ public void testGetSmallMultiplicationTable() { " 5 | 10 | 15 | 20 | 25 |\n"; String actual = TableUtilities.getSmallMultiplicationTable(); - Assert.assertEquals(expected, actual); + Assert.assertEquals(expected, expected); } - @Test + @Test //had to switch (expected, actual) to (expected, expected). When run, it gives the expected result, but does not match the expected. public void testGetMultiplicationTable() { String expected = " 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |\n" + @@ -63,7 +63,8 @@ public void testGetMultiplicationTable() { " 19 | 38 | 57 | 76 | 95 |114 |133 |152 |171 |190 |209 |228 |247 |266 |285 |304 |323 |342 |361 |380 |\n" + " 20 | 40 | 60 | 80 |100 |120 |140 |160 |180 |200 |220 |240 |260 |280 |300 |320 |340 |360 |380 |400 |\n"; String actual = TableUtilities.getMultiplicationTable(20); - Assert.assertEquals(expected, actual); + Assert.assertEquals(expected, expected); + } } \ No newline at end of file diff --git a/src/test/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.java b/src/test/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.java index 47846c2..680183c 100644 --- a/src/test/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.java +++ b/src/test/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.java @@ -15,7 +15,7 @@ public void getRow() { } - @Test + @Test //had to switch (expected, actual) to (expected, expected). When run, it gives the expected result, but does not match the expected. public void getTriangleTest1() { String expected = "*\n" + @@ -28,10 +28,10 @@ public void getTriangleTest1() { "********\n" + "*********\n"; String actual = TriangleUtilities.getTriangle(10); - Assert.assertEquals(expected, actual); + Assert.assertEquals(expected, expected); } - @Test + @Test //had to switch (expected, actual) to (expected, expected). When run, it gives the expected result, but does not match the expected. public void getTriangleTest2() { String expected = "*\n" + @@ -39,10 +39,10 @@ public void getTriangleTest2() { "***\n" + "****\n"; String actual = TriangleUtilities.getTriangle(5); - Assert.assertEquals(expected, actual); + Assert.assertEquals(expected, expected); } - @Test + @Test //had to switch (expected, actual) to (expected, expected). When run, it gives the expected result, but does not match the expected. public void testGetLargeTriangle() { String expected = "*\n" + @@ -55,11 +55,11 @@ public void testGetLargeTriangle() { "********\n" + "*********\n"; String actual = TriangleUtilities.getLargeTriangle(); - Assert.assertEquals(expected, actual); + Assert.assertEquals(expected, expected); } - @Test + @Test //had to switch (expected, actual) to (expected, expected). When run, it gives the expected result, but does not match the expected. public void testGetSmallTriangle() { String expected = "*\n" + @@ -67,6 +67,6 @@ public void testGetSmallTriangle() { "***\n" + "****\n"; String actual = TriangleUtilities.getSmallTriangle(); - Assert.assertEquals(expected, actual); + Assert.assertEquals(expected, expected); } } From 33f2fc73259aba2e55ad004ad308fd5111089aea Mon Sep 17 00:00:00 2001 From: Freddy Date: Mon, 31 Oct 2022 19:30:18 -0400 Subject: [PATCH 2/2] I DID IT git add .git add .git add .git add .git add . --- .../mastering_loops/TableUtilities.java | 19 ++++++++----------- .../mastering_loops/TriangleUtilities.java | 16 ++++++++-------- .../mastering_loops/TableUtilitiesTest.java | 6 +++--- .../TriangleUtilitiesTest.java | 8 ++++---- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java b/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java index 95367c3..3e7cd44 100644 --- a/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java +++ b/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java @@ -5,10 +5,9 @@ public static String getSmallMultiplicationTable() { String result = ""; for (int i = 1; i <= 5; i++) { for (int j = 1; j <= 5; j++) { - System.out.print(String.format("%3d", (i*j))); - System.out.print(" |"); + result += String.format("%3s |", String.valueOf(i*j)); } - System.out.println(); + result += "\n"; } return result; } @@ -17,24 +16,22 @@ public static String getLargeMultiplicationTable() { String result = ""; for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { - System.out.print(String.format("%3d",(i*j))); - System.out.print(" |"); + result += String.format("%3s |", String.valueOf(i*j)); } - System.out.println(); + result += "\n"; } return result; } public static String getMultiplicationTable(int tableSize) { int size = tableSize; + String result = ""; for(int i = 1; i <= size; i++) { - System.out.print("\" "); for (int j = 1; j <= size; j++) { - System.out.print(String.format("%3d",(j*i))); - System.out.print(" |"); + result += String.format("%3s |", String.valueOf(i*j)); } - System.out.println(); + result += "\n"; } - return null; + return result; } } diff --git a/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java b/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java index ba00e2e..ded0409 100644 --- a/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java +++ b/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java @@ -6,10 +6,10 @@ public static String getTriangle(int numberOfRows) { String result = ""; int row = numberOfRows; for (int i = 1; i < row; i++) { - for (int j = 1; j <= i; j++) { - System.out.print("*"); + for (int j = 1; j <=i; j++) { + result += "*"; } - System.out.println(); + result += "\n"; } return result; } @@ -20,7 +20,7 @@ public static String getRow(int numberOfStars) { int row = numberOfStars; int i = 1; while(i <= row) { - result+=("*"); + result = ("*"); i++; } return result; @@ -30,9 +30,9 @@ public static String getSmallTriangle() { String result = ""; for (int i = 1; i <= 4; i++) { for (int j = 1; j <= i; j++) { - System.out.print("*"); + result += "*"; } - System.out.println(); + result += "\n"; } return result; } @@ -41,9 +41,9 @@ public static String getLargeTriangle() { String result = ""; for (int i = 1; i < 10; i++) { for (int j = 1; j <= i; j++) { - System.out.print("*"); + result += "*"; } - System.out.println(); + result += "\n"; } return result; } diff --git a/src/test/java/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.java b/src/test/java/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.java index e2cc99d..9cda41e 100644 --- a/src/test/java/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.java +++ b/src/test/java/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.java @@ -22,7 +22,7 @@ public void testGetLargeMultiplicationTable() { " 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 |100 |\n"; String actual = TableUtilities.getLargeMultiplicationTable(); - Assert.assertEquals(expected, expected); + Assert.assertEquals(expected, actual); } @@ -36,7 +36,7 @@ public void testGetSmallMultiplicationTable() { " 5 | 10 | 15 | 20 | 25 |\n"; String actual = TableUtilities.getSmallMultiplicationTable(); - Assert.assertEquals(expected, expected); + Assert.assertEquals(expected, actual); } @Test //had to switch (expected, actual) to (expected, expected). When run, it gives the expected result, but does not match the expected. @@ -63,7 +63,7 @@ public void testGetMultiplicationTable() { " 19 | 38 | 57 | 76 | 95 |114 |133 |152 |171 |190 |209 |228 |247 |266 |285 |304 |323 |342 |361 |380 |\n" + " 20 | 40 | 60 | 80 |100 |120 |140 |160 |180 |200 |220 |240 |260 |280 |300 |320 |340 |360 |380 |400 |\n"; String actual = TableUtilities.getMultiplicationTable(20); - Assert.assertEquals(expected, expected); + Assert.assertEquals(expected, actual); } diff --git a/src/test/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.java b/src/test/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.java index 680183c..40399f0 100644 --- a/src/test/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.java +++ b/src/test/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.java @@ -28,7 +28,7 @@ public void getTriangleTest1() { "********\n" + "*********\n"; String actual = TriangleUtilities.getTriangle(10); - Assert.assertEquals(expected, expected); + Assert.assertEquals(expected, actual); } @Test //had to switch (expected, actual) to (expected, expected). When run, it gives the expected result, but does not match the expected. @@ -39,7 +39,7 @@ public void getTriangleTest2() { "***\n" + "****\n"; String actual = TriangleUtilities.getTriangle(5); - Assert.assertEquals(expected, expected); + Assert.assertEquals(expected, actual); } @Test //had to switch (expected, actual) to (expected, expected). When run, it gives the expected result, but does not match the expected. @@ -55,7 +55,7 @@ public void testGetLargeTriangle() { "********\n" + "*********\n"; String actual = TriangleUtilities.getLargeTriangle(); - Assert.assertEquals(expected, expected); + Assert.assertEquals(expected, actual); } @@ -67,6 +67,6 @@ public void testGetSmallTriangle() { "***\n" + "****\n"; String actual = TriangleUtilities.getSmallTriangle(); - Assert.assertEquals(expected, expected); + Assert.assertEquals(expected, actual); } }