eclipse project, code, and executable jar file
This is something I whipped up in between posting resumés everywhere yesterday and today. It started on Friday night when I was playing some Settlers of Cataan with my friends and one of them remarked that it was incredibly unlikely that a 12 wasn't rolled more often over the course of the game and asked me what the odds of that happening were, so I wrote a quick program to calculate exactly that and it turned out that there is only a 75% chance of a 12 being rolled when rolling 50 times.
I hadn't done any programming in a few weeks since I was generally tired from my warehouse job so I decided that I wanted to flesh this thing out with a full GUI and multiple variables that you could input and get some more practice with making my GUIs more user friendly.
The cool things of note, beyond the calculation, is that I set up the text boxes with focus listeners that would automatically select the text in it. Then if a text box doesn't contain an integer the program will automatically shift to the offending box and a message will be displayed.
Edit: I was talking to my IT friend about the program and he was impressed by the fact that I was able to do the calculations using nothing but algebra, so I figured I should mention them here. As a physics major and CS minor, I have become pretty good at spotting patterns and I realized that the odds of rolling a number 'N' on 2d6 is equal to:
(6 - |N - 7|) / 36
Once you know that then you just need to set up the correct recursion and you are done.
No comments:
Post a Comment