From 784c22acec190041b2b3013626fa7d5061ec2d76 Mon Sep 17 00:00:00 2001 From: thejoeflynn Date: Thu, 16 Apr 2026 20:18:22 -0400 Subject: [PATCH 1/6] Setup Dice.class --- java/src/main/java/Bins.java | 4 ++- java/src/main/java/Dice.java | 35 ++++++++++++++++++++++++++- java/target/classes/Bins.class | Bin 0 -> 237 bytes java/target/classes/Dice.class | Bin 0 -> 237 bytes java/target/classes/Simulation.class | Bin 0 -> 255 bytes 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 java/target/classes/Bins.class create mode 100644 java/target/classes/Dice.class create mode 100644 java/target/classes/Simulation.class diff --git a/java/src/main/java/Bins.java b/java/src/main/java/Bins.java index b9da83e..12d2bfd 100644 --- a/java/src/main/java/Bins.java +++ b/java/src/main/java/Bins.java @@ -1,4 +1,6 @@ public class Bins { - +Bins results = new Bins(2, 12); // for bins from 2..12 +Integer numberOfTens = results.getBin(10); // returns the number of tens in the 10 bin +results.incrementBin(10); // should increment bin # 10 } diff --git a/java/src/main/java/Dice.java b/java/src/main/java/Dice.java index 2283c96..b78041e 100644 --- a/java/src/main/java/Dice.java +++ b/java/src/main/java/Dice.java @@ -1,4 +1,37 @@ + +import java.util.Random; + public class Dice { + private int numberOfDice; + + public Dice(int numberOfDice) { + this.numberOfDice = numberOfDice; + } + + public int tossAndSum() { + Random random = new Random(); + int sum = 0; + for (int i = 0; i < numberOfDice; i++) { + sum += random.nextInt(6) + 1; + } + return sum; + } + + public static void main(String[] args) { + Dice dice = new Dice(5); // for yatzee + Dice dice1 = new Dice(2); // for craps + + Integer toss = dice.tossAndSum(); + Integer toss1 = dice1.tossAndSum(); + + System.out.println("Toss and sum of 5 dice: " + toss); + System.out.println("Toss and sum of 2 dice: " + toss1); + } + + + + -} + +} \ No newline at end of file diff --git a/java/target/classes/Bins.class b/java/target/classes/Bins.class new file mode 100644 index 0000000000000000000000000000000000000000..23359a899901cabd074a7cbe3b1f8535b0f90326 GIT binary patch literal 237 zcmXX=IS#@=5cA}Oa7Fxp4k$=T0ipnjDuM!(eiK%(C?rx2{zZjE!2@^{Vm6|&$DYIU z`M%x&=I~t@1Z%Cb(uGCvui`F(RAlF1A75os5uByURJ9_Q<4MG`oBSj_m}qxl!yybp zmC0Rwi)C>XaViPJFi%7pi9%`pH?8WTO1>8AtOdb4 literal 0 HcmV?d00001 diff --git a/java/target/classes/Dice.class b/java/target/classes/Dice.class new file mode 100644 index 0000000000000000000000000000000000000000..64cb218f0697be6580903143e503480efb5390df GIT binary patch literal 237 zcmXX=I}Ui)1G!Xm%s}?FD literal 0 HcmV?d00001 diff --git a/java/target/classes/Simulation.class b/java/target/classes/Simulation.class new file mode 100644 index 0000000000000000000000000000000000000000..a009af16d9931c72f4ed3f88092e1a9a2d8ad349 GIT binary patch literal 255 zcmYLDI|{;35S)$qXpBa@ft^~I(n7Hjtb!Jb{Y!l4lYAg1-pfj`@Bki4+!us2Gdr`p z%zVDDH-I??4h(|3S80`qQstQglQ6i7y9g4Ior7I;m2pY1mnu``iqINQjs$a^pQMWx zIvy<81V2=n+*WBMi-U*~Nf?HCERv%rl-7UKEHCOt@WLi>q4V>qh~-A Date: Thu, 16 Apr 2026 20:18:32 -0400 Subject: [PATCH 2/6] fixed up Dice.class --- java/target/classes/Bins.class | Bin 237 -> 729 bytes java/target/classes/Dice.class | Bin 237 -> 1700 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/java/target/classes/Bins.class b/java/target/classes/Bins.class index 23359a899901cabd074a7cbe3b1f8535b0f90326..c4363ee175b39fe40ccc76c1fa49c18a19284662 100644 GIT binary patch literal 729 zcmaKq-)q!B5XWb)=cS3!t5>T&uJ?2YrF{_uDx7qE4v&egtAcC~-JJi~$n zBp%z&P%B_C3*3Q#+;;U6{c*KG%lq52>!?FZxI)j+;HkEno(b5POi#GROIKn7w*(BY z>DS&nzX?Mjx(}A?ICGArEL`1aqewd|8}F6|>-LGv(#0vV&$i^df}EG3n~AoxE7?q? zZe?dnthB}Q3a*h(T`5;cj0SQYk`*T*PD+;z#%x(SzqF(-B!o;fiy3W$H>43mf;5g2n-Q@ diff --git a/java/target/classes/Dice.class b/java/target/classes/Dice.class index 64cb218f0697be6580903143e503480efb5390df..a0271aa8cd64ee507bd82c3f3071057ff2f1f27e 100644 GIT binary patch literal 1700 zcmaJ>U31$+6g}%N*@_(J11C65gG(A}Cv8nbOKIE`8kbNPCnQ+PVnsVLWjCp&eOZb{hRTfY^ z$93=8t$MHRV^$SR3^?{Y(<(jE?UvJ4k;RZ4avG*^PC&7ZAH1qf@{*t=-1Qx0TED2y<09eR91LVR-Ba92O7rlj*0^2 z6%++VPoyLjW7p_vSiohnJJ7A3v9Tj@tHls-->sa&ReY$RG$=L5dgyvaTf;RhlCjfc zaoHf&bV?7&$RjU9ZfK#t9zWw!c-ZpWG%lxWT*?-rZ-~)AW`Vdoq?1~Adfle6YRb+`$>zH%Nm9WT z$MIaRt9RB6Z_jDDD%SB(!3Hn>EkInI8sQx3807aiI;6}WlWG0t!gOLE4|_8}^|Wz|j3C}$E_OJY+Xw@D@PB$Ma2 zkau?SH}X=zrMyUjANU)`i-Tjn4^`VXx)n=zUBgwdB{27fG-nm7;EBM@+g;^b;46a* zy!t2`QXnFq6k1W*{PZ}cxLW0YgtIz-%>TK+kp6?K2r?Xp{m3L@^h`m;2=^ueZ;V2= zIpcg(z5?J_*q^v^`b4f7$|?m)VUm1vWIlyiGF&9P74nl6To2Nsf_q%0*yf+pm+vdzr&W#- t#uV`d?vvmwYpBwS(SAVh2);y(^DwPPjH&zM*Lci5`H+5tZ}A;+{{!0%g1-O& delta 135 zcmZ3&`<9XG)W2Q(7#JAL83ZPBDM_-~Waed-*fBCNYiNcsGO#%3r=)T*Ff(vY%(R~@ zz$_NbpvVA}1ZrRa(u@qO3~WG>9mvxM^BEXewYD>GYy=80F>nD%kTggsH<083vsr;O NFIbEZNHQ_-0{|Iy4>$k- From 074f86c6e76afb39f40556f336ecf90fb8be4ed0 Mon Sep 17 00:00:00 2001 From: thejoeflynn Date: Thu, 16 Apr 2026 21:45:36 -0400 Subject: [PATCH 3/6] Added tests --- .vscode/settings.json | 3 +++ java/src/main/java/Bins.java | 1 + java/src/main/java/Dice.java | 4 ---- java/src/main/java/Test.java | 23 +++++++++++++++++++++++ java/target/classes/Test.class | Bin 0 -> 128 bytes 5 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 java/src/main/java/Test.java create mode 100644 java/target/classes/Test.class diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c995aa5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.debug.settings.onBuildFailureProceed": true +} \ No newline at end of file diff --git a/java/src/main/java/Bins.java b/java/src/main/java/Bins.java index 12d2bfd..e3727b9 100644 --- a/java/src/main/java/Bins.java +++ b/java/src/main/java/Bins.java @@ -3,4 +3,5 @@ public class Bins { Bins results = new Bins(2, 12); // for bins from 2..12 Integer numberOfTens = results.getBin(10); // returns the number of tens in the 10 bin results.incrementBin(10); // should increment bin # 10 + } diff --git a/java/src/main/java/Dice.java b/java/src/main/java/Dice.java index b78041e..a67a2c3 100644 --- a/java/src/main/java/Dice.java +++ b/java/src/main/java/Dice.java @@ -29,9 +29,5 @@ public static void main(String[] args) { System.out.println("Toss and sum of 2 dice: " + toss1); } - - - - } \ No newline at end of file diff --git a/java/src/main/java/Test.java b/java/src/main/java/Test.java new file mode 100644 index 0000000..e9ff6f1 --- /dev/null +++ b/java/src/main/java/Test.java @@ -0,0 +1,23 @@ +import static org.junit.Assert.assertTrue; + +public @interface Test { + +public class DiceTest { + @Test + public void testTossAndSumWithOneDie() { + Dice dice = new Dice(1); + int result = dice.tossAndSum(); + assertTrue (result >=1 && result <= 6); + } + + @Test + public void testTossAndSumWithTwoDice() { + Dice dice = new Dice(2); + int result = dice.tossAndSum(); + assertTrue(result >= 2 && result <= 12); + } + +} + + +} diff --git a/java/target/classes/Test.class b/java/target/classes/Test.class new file mode 100644 index 0000000000000000000000000000000000000000..bb6235c6a23f7e6657a117e4a329fdb749b3aaf2 GIT binary patch literal 128 zcmX^0Z`VEs1_pBmPId++Mh2FU)Z!9$1{OvJfvm)`ME#t^ymWp4q^#6rpeP$7gFHes zF)uH_B(WqjKTqEg&SYfZ3eGPrN=|jl%t>Wr-~<_`2hyX)$iT?J48*KJ+Zcc}JCI~z G-~a&Qb{|my literal 0 HcmV?d00001 From 24e3ae60d3d0246c80de7266cc953a753338da56 Mon Sep 17 00:00:00 2001 From: thejoeflynn Date: Thu, 16 Apr 2026 21:54:21 -0400 Subject: [PATCH 4/6] fixed tests --- java/src/main/java/Test.java | 30 ++++++++++++++---------------- java/target/classes/Test.class | Bin 128 -> 1227 bytes 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/java/src/main/java/Test.java b/java/src/main/java/Test.java index e9ff6f1..6ab5bd9 100644 --- a/java/src/main/java/Test.java +++ b/java/src/main/java/Test.java @@ -1,23 +1,21 @@ -import static org.junit.Assert.assertTrue; -public @interface Test { +public class Test { + + public static void main(String args []) { + Dice dice1 = new Dice(1); + int result1 = dice1.tossAndSum(); + if (result1 >= 1 && result1 <= 6) { + System.out.println("It works " + result1); + } -public class DiceTest { - @Test - public void testTossAndSumWithOneDie() { - Dice dice = new Dice(1); - int result = dice.tossAndSum(); - assertTrue (result >=1 && result <= 6); - } + Dice dice2 = new Dice(2); + int result2 = dice2.tossAndSum(); + if (result2 >= 2 && result1 <= 12) { + System.out.println("It works " + result1); + } - @Test - public void testTossAndSumWithTwoDice() { - Dice dice = new Dice(2); - int result = dice.tossAndSum(); - assertTrue(result >= 2 && result <= 12); } -} - } + diff --git a/java/target/classes/Test.class b/java/target/classes/Test.class index bb6235c6a23f7e6657a117e4a329fdb749b3aaf2..dd0d9e50e39d9ac8b90863cc5426d0656c81cb95 100644 GIT binary patch literal 1227 zcmaJ=+fGwK6kS6vht>)OEQq33rPzW{LBvZ{E+xb!1x-q7j88*5fkRKvY0jBq_!D1^ zU!V_|XyOO>?&oM+(>7cJ@ntS+*6h9Z+B3iYe*X#JG1e{g352&*pe=+2lKb*N<{jzo z=3npZtC|*wKDS+4zZ3{%b5(MSUR}izLM(v@q5^|u+f`fb=8p2W<&L8ShRa?}I#uc0 zX5RzDde06Rt!#1?7^f+1S70>zzI>9iqJ7)lE##^ehDcerYfP2Ih)H#YK(>^t8elYm zFB_uu(%3^MEnfv~M-vjI-todQ%GKqHmbJ#FZ1p-3 zuXt_0rZ#NTtC(rWoKZ~6);v!K+Lx_OrT4sg5a$bdYT=2%H)1~#;-GHy8TX$42S@yg}yHz;vz$xU+#qGnEx`2M#pYC%lobF67L{U0U z#n!4Y7{yXQUhvtJboztmH-fYfNR(Vx`9((tfeI|F2xQI`dy#w#YXUd_Pc>cY)JkXg z^!U7hKCbw2I9lB0ISbB_>2K)&(m9TEG{=T|iDRNm;Cz|87zQv%#9aQ(kP*(CKahME z{>G0tbA;53iSQ?+CX&(582pOyiSM`t9O14ZMM&D3C21*~3P(D$#4#<`p&1b&7!gxU zMr9nMOln~q{m4+#9HlH$%nH#mhB_h_yFxIH8QzIu9rrOynFClRKhIL;DB}UK5bus- vo>&+Qff$?3=9nB44f0W6ja$6*cch)vl7b^^>Y&Q()APb^72a(OEUBG^c~^M c$-fyTCDa%h7#Wy>m=&m-0Z6k0NhSsk03oCl7XSbN From 58e0f9323326c1ba772290f0396360d8eb090bc5 Mon Sep 17 00:00:00 2001 From: thejoeflynn Date: Fri, 17 Apr 2026 08:30:18 -0400 Subject: [PATCH 5/6] setup Bins --- java/src/main/java/Bins.java | 25 ++++++++++++++++++++++--- java/target/classes/Bins.class | Bin 729 -> 595 bytes 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/java/src/main/java/Bins.java b/java/src/main/java/Bins.java index e3727b9..5645a5c 100644 --- a/java/src/main/java/Bins.java +++ b/java/src/main/java/Bins.java @@ -1,7 +1,26 @@ public class Bins { -Bins results = new Bins(2, 12); // for bins from 2..12 -Integer numberOfTens = results.getBin(10); // returns the number of tens in the 10 bin -results.incrementBin(10); // should increment bin # 10 + private int min; + private int max; + private int[] bins; + + public Bins(int min, int max) { + this.min = min; + this.max = max; + this.bins = new int[max - min +1]; + } + + public int getBin(int number) { + return bins[number-min]; + } + + public void incrementBin(int number) { + bins[number - min]++; + } + + + + + } diff --git a/java/target/classes/Bins.class b/java/target/classes/Bins.class index c4363ee175b39fe40ccc76c1fa49c18a19284662..c94c319acc55f508d09856b3026e092a6d9fde38 100644 GIT binary patch literal 595 zcmYk2K~KU!6oh9>1*sJ(ASy-08}tB24;o`MF*YH3&~VX%1va__N`h$oQC>_WCdT*! z{87f)g@A3cef!?*H?#fu{rm>7kG&Ku0sBP7k15y!UN3r%8vQ7~Z(O!}vNIM)3{)&2 zLS02K6t^iBux{8%9;#T4j|7&gVOVQ%cslG#2MJ_cILPu$wbn{QV9mu6lDf*fNKLDC z7t2TsWSc6M7f*w>99>84z7)tchn=Y3ibhKBXH9$jplFa+(e?&X*zO{-x|hlveB zz*TW)BnL8Hj2X?j8a|CW@=R%iv}V-xWwFOh3I2=(EFF=Rr30ET(*bXwdet=^|_4U7TKe2&UH~XbAfH_%xLFKq*dO6c3Zda YE*HriGtVK5{6DHUr+RbhE;$w|fA79dhX4Qo literal 729 zcmaKq-)q!B5XWb)=cS3!t5>T&uJ?2YrF{_uDx7qE4v&egtAcC~-JJi~$n zBp%z&P%B_C3*3Q#+;;U6{c*KG%lq52>!?FZxI)j+;HkEno(b5POi#GROIKn7w*(BY z>DS&nzX?Mjx(}A?ICGArEL`1aqewd|8}F6|>-LGv(#0vV&$i^df}EG3n~AoxE7?q? zZe?dnthB}Q3a*h(T`5;cj0SQYk`*T*PD+;z#%x(SzqF(-B! Date: Fri, 17 Apr 2026 13:23:40 -0400 Subject: [PATCH 6/6] setup Simulation and testing --- java/src/main/java/Simulation.java | 37 +++++++++++++++++++++++++++ java/target/classes/Simulation.class | Bin 255 -> 2279 bytes 2 files changed, 37 insertions(+) diff --git a/java/src/main/java/Simulation.java b/java/src/main/java/Simulation.java index 73d86e8..1f5e9af 100644 --- a/java/src/main/java/Simulation.java +++ b/java/src/main/java/Simulation.java @@ -1,5 +1,42 @@ + public class Simulation { + private int numberOfDice; + private int numberOfTosses; + private Dice dice; + private Bins bins; + + public static void main(String[] args) { + Simulation sim = new Simulation(2, 10000); + sim.runSimulation(); + sim.printResults(); + } + + public Simulation(int numberOfDice, int numberOfTosses) { + this.numberOfDice = numberOfDice; + this.numberOfTosses = numberOfTosses; + this.dice = new Dice(numberOfDice); + this.bins = new Bins(numberOfDice, numberOfDice * 6); + } + + public void runSimulation() { + for (int i = 0; i < numberOfTosses; i++) { + int result = dice.tossAndSum(); + bins.incrementBin(result); + } + } + public void printResults() { + System.out.println("***"); + System.out.println("Simulation of " + numberOfDice + " dice tossed for " + numberOfTosses + " times."); + System.out.println("***"); + for (int i = numberOfDice; i <= numberOfDice * 6; i++) { + int count = bins.getBin(i); + double percentage = (double) count / numberOfTosses; + int stars = (int) (percentage * 100); + String asterisks = "*".repeat(stars); + System.out.printf("%2d : %8d: %.2f %s%n", i, count, percentage, asterisks); + } + } } diff --git a/java/target/classes/Simulation.class b/java/target/classes/Simulation.class index a009af16d9931c72f4ed3f88092e1a9a2d8ad349..e9838853810a30a5bba6e7ebda5990caeaa8429b 100644 GIT binary patch literal 2279 zcmaJ@U2_vv7=BLEWZSsVHqaJGfwZ)crqWhKK++<#r4kGj2_HuM+9s#zl4Lh-Hq|Ql zMIG+E_SP9^yzolLwhWB^0Dp=9K}USf**IyZ)yyR4?0ep?=Xu}rZhrs!>2Cne;%ftK z0@0jZZB#7Zb{zxl0^Rqm6>FkmIi-n(#rv}03z$x$x+uMcr8&DG1w=+*@4up3ZoMw+ z0_{b87Rf4|G@lo3hvGD^YvjE(tP3-LBGcwiPxVMF@i`*}hKZcFaT=5w#mJVIX4Q z1VJe>qBxFGrI(^0NhnI`MH3z9G%!w?VknA}=vD_WnTX;AO8sS<(&IR7;uV}>oqRHV z$tmU&rQp2knMa=uk4U$bf&XD2S;qJh`86*{+C z_hr?@CCt#b+hEOmgEHCf#0^CzDxY<1pLV;?PH*+6MqdUI}rovB=~ zl)cHht%kuF?dDN7Q33lQqM2rlsa=TP+R(w3PB-0cuNrS@xZpM%@(`^_ufT4yO6tC| z=3!RDV=+1{c8X`$%iPCyGNs0e+o0*Zt?pS@>$;39eh6{Kb^W^US+#4@Uv`UZ@sII| zfmMOw7K664;+Ew^Fdl-Yn70bP>#eG8`BdQBtuUL~fx|17Q>@7PaMpFpjaqtVid!Vx z3~#O0%9! z2Y{Jz9O=zgEHz0De8~~AgNoh28F(acevSM@!S8CHao=M7}Y>GYJ7Fm&3^9Ul=LwS zjWK}3Tuo{m!BM*AjiF5t;vv&esg0#Jkx0eYF_aou$8hQyj_2c>NUrnb8BXTo@$Sg- zCMMP~*$R9}W7x~^U3A{foO^JHu2a~j6G#NEaf)HpXH26PdZ+NWF$um^nyEbCvr1(! zH1z}eQon#GU!LYVIk17VYeK}iAO7z7A1Z+m11W^z=5IeqJD{B~?Q>19#6yl(%<{UlGcO;!p5?F5f<&m+O~M6T zp|vInNsiorgwuTAIGTiMoP&!R3B8O-d`MZCUQWP6oqI)5r=n;~{D~};d3YELLwwFB^)KNIe1$a}{0FZ5{Br;R delta 159 zcmaDZ_@9yM)W2Q(7#JAL83ZPBX~?nJWaed-*fBCNYiNcsGO#%3r=)T*Ff(xSFt9SP zO?bK}xxSBoCO)3Z!|#Vthc7iGd#gA?+5z