This simple application is an exploration into a solution to the Monty Hall problem. Though the application explores the Monty Hall problem, this fork attempts to illustrate how improving the readability of the code base can make the solution easier to understand. Even with minimal commenting.
The main class is MontyHallProblem
and can be run without providing arguments. It creates a counter to keep track of
the results and prints a summary of results and the end of execution. For each iteration (or contest) run, a collection of doors is created to keep track of the contestant and host selections.
mvn exec:java -Dexec.mainClass="MontyHallProblem"
You must edit the constants in the MontyHallProblem
class:
NUMBER_OF_TRIALS
: A larger number provides a higher confidence in the statistical result.NUMBER_OF_DOORS
: 3 is the most common, but any number will work.
Is handled by slf4j - check the configuration in the resources directory.
- Loops through the specified number of trials.
- Creates a structure representing the doors, where only one hides a car.
- A random door is selected by the contestant as their original choice.
- A random door that is a goat is revealed to the contestant.
- A random door is selected by the contestant as their switch selection.
- A running count of choice outcomes is kept.
- Finally a summary of the outcomes is printed.
From the June 2015 Philly Java Users Group Meeting.
We had a side discussion on code commenting a few people wanted the discussion documented for future reference.
@mgeiser added the slide deck and created this example repo.
- The slides of interest regarding commenting are the last 5 slides of the deck.
- This fork intends to explore an alternative school of thought.
Comments highlight code that can be improved.