From 7b755a24693e8c6d6e36ad9aa3e32186e0cd755e Mon Sep 17 00:00:00 2001 From: collin-beck3 Date: Thu, 16 Apr 2026 17:40:57 -0400 Subject: [PATCH 1/4] dice created with n number of dice to roll, and a simulation that rolls the dice. --- java/src/main/java/Dice.java | 20 ++++++++++++++++++++ java/src/main/java/Simulation.java | 9 +++++++++ java/target/classes/Bins.class | Bin 0 -> 237 bytes java/target/classes/Dice.class | Bin 0 -> 650 bytes java/target/classes/Simulation.class | Bin 0 -> 1219 bytes 5 files changed, 29 insertions(+) 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/Dice.java b/java/src/main/java/Dice.java index 2283c96..9d2810e 100644 --- a/java/src/main/java/Dice.java +++ b/java/src/main/java/Dice.java @@ -1,4 +1,24 @@ +import java.util.Random; + public class Dice { + private int sides; + private int numberOfDice; // stores the number of dice to be rolled + private Random random; + + public Dice(int sides, int numberOfDice) { + this.sides = sides; + this.numberOfDice = numberOfDice; + this.random = new Random(); + } + + public int roll() { + int total = 0; + for (int i = 0; i < numberOfDice; i++) { // loop to roll each die one by one + total += random.nextInt(sides) + 1; // adds each roll to the running total + } + return total; + } + } diff --git a/java/src/main/java/Simulation.java b/java/src/main/java/Simulation.java index 73d86e8..cf732fc 100644 --- a/java/src/main/java/Simulation.java +++ b/java/src/main/java/Simulation.java @@ -1,5 +1,14 @@ public class Simulation { +public static void main(String[] args) { + Dice dice = new Dice(6, 2); // Create a dice object with 6 sides and n dice to roll + System.out.println(); + System.out.println("Rolling the dice..."); + for (int i = 0; i < 10; i++) { + int result = dice.roll(); + System.out.println("Roll " + (i + 1) + ": " + " Total: " + result); + } +} } 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..9727645ed03f6a930210687f142d5fcebe571e6a GIT binary patch literal 650 zcmYk2&2G~`6ot>&PTT}1O-)H?6KE+ZBwmmu3j!MulBGZ;iXyS=#4&VQ*G8^`ShC5nV#Gs@-1cw{I|6PRzb?X*6FY-& z$YCo*R!9~KCD7O}WOV#UzATyb{cMp(@k6CmYZ`n@Z-69%xmg>Q9*H+g4`fbyHmBh5 z7g*;pI%K7;-we*s2)awOg5DB-@D=ON&d^?>^U?Hd@ZTm8WH{`vk%d2Lk literal 0 HcmV?d00001 diff --git a/java/target/classes/Simulation.class b/java/target/classes/Simulation.class new file mode 100644 index 0000000000000000000000000000000000000000..0863a07054543df24e2373ea8d46732eee124a19 GIT binary patch literal 1219 zcmaJ>+fGwK6kXGn9w@~Y5Rj|orUkTByi-7>NNiHnSW;traVQfwaC%O2&Xk0AKf+g^ zd{rMH!Nd>nL;MRbYg!T@G^Ux`-h0+wYwtPz`RDitfCpH!5E6)$>}uVS+V)%v5rO2c z+?QELy4%^8o4cx_1)__#YwKl!aC)XJ5XpO6DuysR;%GxuAW^hk^`c(gRQ`tCbd*3( z(W^+OEPdOYPmB@0V+R89;%UYl(W=sR1^UzPil>=N+PB^9+)UX*H$ztK3KJ&LYZ6`- zXiFCgGvyBSDfmYQx1~EjwUY+#&n!vV~eMMAFY$dC?7)CH=VN{^Ek@vhi zj;ltQRWmmnw;kh*d+j+6X{GdzN^Ox+CX+EJlO}kIdD5*E7~a?7xQ;Z1_(W)wvCzX7 z%*HW?8v+AWxu^1;Tao&Wt#`N!v~)FV)o+AeL?x2+x9RU~Q8YRYIkv56>c$cao1;L3 zuY$V6igcBa=IJyYKC(Y_oMuHEXh>J^#SSTom|twmv7(O~B{U-EvegRrI{QdM$TR@EOawiyH?u z)gt_CRho}DceaWr5P9i1C0napB8rFYcr4IuI-C*p9P-;5aNzs6=#d5ELXv`ZT1N5UmNZiXX6G(C+B!G zfNK{|9k_%9E#~qUMEC<1za#lJ8Ere_clix{hZyGElRCsicF+O-GYpe+0_~h5%o#;D@dtSxW4=jx=ef_3f#EaT%!!-G@YIRh6mg4; zhLPfao&qPy@D6uj++{=zq2K09Op1P5?$Hv$ef~Xxm;y^2%Xrd=6L^X|o?-AG?Y|$g literal 0 HcmV?d00001 From f8cde13ccd82fd5d6ae84210b10e8ea2ad201db2 Mon Sep 17 00:00:00 2001 From: collin-beck3 Date: Thu, 16 Apr 2026 18:00:24 -0400 Subject: [PATCH 2/4] added bins and simulation for total count --- java/src/main/java/Bins.java | 18 ++++++++++++++++++ java/src/main/java/Simulation.java | 13 ++++++++++--- java/target/classes/Bins.class | Bin 237 -> 582 bytes java/target/classes/Simulation.class | Bin 1219 -> 1467 bytes 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/java/src/main/java/Bins.java b/java/src/main/java/Bins.java index b9da83e..84d75d6 100644 --- a/java/src/main/java/Bins.java +++ b/java/src/main/java/Bins.java @@ -1,4 +1,22 @@ public class Bins { + private int[] counts; // Array to store the count of each possible outcome + // Constructor to initialize the bins based on the number of dice and sides + public Bins(int size) { + this.counts = new int[size]; + } + // Method to increment the count for a specific outcome + public void increment(int value) { + counts[value]++; + } + + // Method to get the count for a specific outcome + public int getCount(int value) { + return counts[value]; + } + + public int getSize() { + return counts.length; + } } diff --git a/java/src/main/java/Simulation.java b/java/src/main/java/Simulation.java index cf732fc..69e3bcc 100644 --- a/java/src/main/java/Simulation.java +++ b/java/src/main/java/Simulation.java @@ -1,13 +1,20 @@ public class Simulation { public static void main(String[] args) { - Dice dice = new Dice(6, 2); // Create a dice object with 6 sides and n dice to roll + Dice dice = new Dice(6, 2); // Create a dice object with 6 sides and n dice to roll + Bins bins = new Bins(13); // Create bins to store the counts of each possible outcome System.out.println(); System.out.println("Rolling the dice..."); - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 10000; i++) { // loop to roll the dice n times int result = dice.roll(); - System.out.println("Roll " + (i + 1) + ": " + " Total: " + result); + bins.increment(result); // Increment the count for the rolled result + System.out.println("Roll " + (i + 1) + ": " + " Total: " + result); //print result + } + + System.out.println("\nResults:"); + for (int i = 2; i<= 12; i++) { + System.out.println("Total " + i + ": " + bins.getCount(i) + " times"); } } diff --git a/java/target/classes/Bins.class b/java/target/classes/Bins.class index 23359a899901cabd074a7cbe3b1f8535b0f90326..21f4c5bac7d04a8c7e869c748fe233f5c31202ff 100644 GIT binary patch literal 582 zcmZ9HJ5K^Z6ot>gvco=9#J6Z+rxajkfw7RpXhNjG&}iYZPIL$^2`m);CL0rti81^D zf0XgeE?E+rxsSQ$yXXG=e$4=!U|%99V4dq|EMW7vvtD`PMbNHZKUqzXl-gFJZehpZKm^BMVS?qSi?GL0vj2%Nrj<$)psma?rPS3djWORFSwL0fL;dl zxFQ8^VS8?~L5%^*1Xz1znmV*O0Ady(nSo>m+QIG|bj)ZJwgJulbJi1%pH9p<0+nRj F-XG-zOV0oR delta 124 zcmX@c@|Kb7)W2Q(7#JAL83ZPBDNER7=4F=HF)}b~XofK|usG+Zq;fGZGjL8!v77i< z!Ha=`5eQis*nlKEP?tWK&%nT{wVi=uBT#^efeT22q(N+MAjtz}vjS;eAdiuO4=lqE E0M3XH@Bjb+ diff --git a/java/target/classes/Simulation.class b/java/target/classes/Simulation.class index 0863a07054543df24e2373ea8d46732eee124a19..db5596c1c613b41d4fe23cd3b3ddd1eec836daf3 100644 GIT binary patch delta 745 zcmX|9O;giQ6g{sAO&TJk?Sv1ZHGD}5wJ1fxW+}9DKolY=guGC4`Ag#0B_K7bML$7-gEDH_r255NvHJVy!{Qp95$QM_Yna- z4E$2nb|k3ilhJ{G0`z>M9Krx%0tTBuRW6Qe%`+`H1R@N3-K?)MiXemVzFxIm%NB8+ zAzIqAtg2nn+_$Forn+OMQYi^T&}EDw!Jz7eUE{!*vJAU2wdNADl1-E)D43Ly#0?r- zrw$C9p2+)Zrexgo)r6|{PTj1Twi_Yg(=yVS@jkM2R>Ul2rIP9FTdtGwId^2-MTSAF zm~L)w-**3ACLaOAG@Xrl#UZI%-Vsv=eUS{o!ZP_RC12AT{McWI_nVc2Pf-xC;;jS{ zVj4w;PkO>v1$Xx-q?p$kw1s4O0hQtcyx c19*%l&1aafg4ly!LBpC!( z+4u)!_JS+7>LNm06mjPd5jQUU0e+mRn{v5_bKmp6=e_ry{leG0{q4`*C*Ue~U)i5^ zo-s~YoK(0^{O7(G`cd0!z39imQ-^UTl8n-W64Mq_iW7&FPS@M&b)vWx_X1y7r^za; zXDJj$InD@gyBmg`sIBA2f!^)x1oe8|ro?PYo>PogHjkLaqHH&-_ibFxI-H}T$n>Ox z!mLy`isWG4p~m^-i&{$N3@_O+TG?wfEgH#zQ8jC&AZA z&`RNKL{ZRN5B+{W=v&-Ul#`!E*|fNw{4xgv-jR_7EBm+)-0ZQB6gNLGI%HB}Q4g6h zSKl&G8&X~qq?CCywMP}C@X}Bv*M9T&`+L!w*b-;bJ4?R;Sw^trBXdlXXI83h~zj+l9^l*hK=z%9fqsM1i37T!4;V$(p0f3dyN~1 LJjG4cxx@HB_+MM? From 82e4aa1575b981a3b9bf497dc8143f422e06ac46 Mon Sep 17 00:00:00 2001 From: collin-beck3 Date: Thu, 16 Apr 2026 18:56:12 -0400 Subject: [PATCH 3/4] dicey update, need to add hisogram --- java/src/main/java/Simulation.java | 8 +++++--- java/target/classes/Simulation.class | Bin 1467 -> 1803 bytes 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/java/src/main/java/Simulation.java b/java/src/main/java/Simulation.java index 69e3bcc..340123a 100644 --- a/java/src/main/java/Simulation.java +++ b/java/src/main/java/Simulation.java @@ -3,10 +3,11 @@ public class Simulation { public static void main(String[] args) { Dice dice = new Dice(6, 2); // Create a dice object with 6 sides and n dice to roll Bins bins = new Bins(13); // Create bins to store the counts of each possible outcome + int numrolls = 1000000; // Number of rolls to simulate System.out.println(); System.out.println("Rolling the dice..."); - for (int i = 0; i < 10000; i++) { // loop to roll the dice n times + for (int i = 0; i < numrolls; i++) { // loop to roll the dice n times int result = dice.roll(); bins.increment(result); // Increment the count for the rolled result System.out.println("Roll " + (i + 1) + ": " + " Total: " + result); //print result @@ -14,8 +15,9 @@ public static void main(String[] args) { System.out.println("\nResults:"); for (int i = 2; i<= 12; i++) { - System.out.println("Total " + i + ": " + bins.getCount(i) + " times"); + double percentage = (bins.getCount(i) * 100.0) / numrolls; + System.out.printf("Total %d: %5d times (%.2f%%)%n", i, bins.getCount(i), percentage); } } - } + diff --git a/java/target/classes/Simulation.class b/java/target/classes/Simulation.class index db5596c1c613b41d4fe23cd3b3ddd1eec836daf3..ad06ade7b25b225d5f494891ad6453ed9396c6c8 100644 GIT binary patch delta 1057 zcmZuvO-~a+7=EU^+bzqYrMMz0u!5_tLQ&+))&K&2R6&uVSn-3k47IS`Htp8LQ;jk4 zpouYi@?v5%@vMhJM2%kk2`1jXc<>L1?^Y8raVI8RUYuWZ41ir@WcGWo7M*?%d+~Vm8gA(WrtBM7-n!3|e?{Q!$5_nRw)q zf*`t7bR)_j7D<6Y2uBhM+B6(eaTqNOby+)It zh7mDr1;;TiV~nBk?}ih$!!x|7Vge`V;I~by%q!=Y7`BuCri1;-iz_&VgpAYwSUiz0 z-?X@=amMpwVl(kKM!XJ8s+ht#27k?7s&VW;*3C~YyK_SG)_*T1?(X%C3^R7DRVnkX)4(p&Tb zlyYBWn%Me$B1l2!o(k7T=@sU+lII~_uX^vIrqN2_qM&>s(e2>{0d+SYx~O2 zNEAIt$~d$CSC>-g4WeX(`!FD*Kgd$o-XOvRdAm~feAkQMEFrPD<+^3BWcV)~<9T`A zu`EkLA50a4$Pje1_{!e3v##xxvP(WIOVgPZ1saA`jNm*$RM>$anVEtD9a$9@&`pSz zz4eN->3Dve*BezahVkGVO<0p$Qx=`-j_X%*4aFrDmyshxN{*l3+VOn$Gz*zR9E8!J zSDNjmGJy(&aHT0Dv@QAe`o_Gyy=*^oo#4GR9=?mBjC;WkDI9urb0#EZQi2!!~SyLD)5S~zroc(D$BO=~+q=lmC(uEAi8r)wCJW=TPt|QO$ESzGmJWngGB6&jIWLXU22&N28hEAzOf_rZ<-GbY=!?B%D U3+#Eni4U>FoWl7sZ?uZ;e-6`y!vFvP From 9686f400f88f7b2a1133f7cc72963e6716a27d80 Mon Sep 17 00:00:00 2001 From: collin-beck3 Date: Fri, 17 Apr 2026 10:12:27 -0400 Subject: [PATCH 4/4] added histogram --- java/src/main/java/Dice.java | 2 -- java/src/main/java/Simulation.java | 16 ++++++++++++++++ java/target/classes/Simulation.class | Bin 1803 -> 2315 bytes 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/java/src/main/java/Dice.java b/java/src/main/java/Dice.java index 9d2810e..8e3a878 100644 --- a/java/src/main/java/Dice.java +++ b/java/src/main/java/Dice.java @@ -19,6 +19,4 @@ public int roll() { } return total; } - - } diff --git a/java/src/main/java/Simulation.java b/java/src/main/java/Simulation.java index 340123a..bf65106 100644 --- a/java/src/main/java/Simulation.java +++ b/java/src/main/java/Simulation.java @@ -18,6 +18,22 @@ public static void main(String[] args) { double percentage = (bins.getCount(i) * 100.0) / numrolls; System.out.printf("Total %d: %5d times (%.2f%%)%n", i, bins.getCount(i), percentage); } + + System.out.println("\nHistogram: "); + for (int i = 2; i <= 12; i++) { + double percentage = (bins.getCount(i) * 100.0) / numrolls; + String bar = makeBar(percentage); + System.out.printf("Total %2d: %-20s %.2f%%%n", i, bar, percentage); + } +} + +public static String makeBar(double percentage) { + int blocks = (int) percentage; + String bar = ""; + for (int i = 0; i < blocks; i++) { + bar += "*"; + } + return bar; } } diff --git a/java/target/classes/Simulation.class b/java/target/classes/Simulation.class index ad06ade7b25b225d5f494891ad6453ed9396c6c8..8881b5322c0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