Question: In Java: In this project we will create a simulation to investigate a question that is at the basis of Hot Hands and is also

In Java:

In this project we will create a simulation to investigate a question that is at the basis of Hot Hands and is also related to the Gambler's Fallacy:

In a trial consisting of 100 coin tosses, what is the conditional probability of obtaining a fifth head after four heads? The Gambler's fallacy can be summed up in the gut feeling that after a run of four heads, the next coin toss is bound to be a tail. We know that the coin tosses are independent, so that gut feeling, no matter how strong, must be incorrect. What if we measure how often you get a fifth head in an actual trial by counting how many hhhh's are followed by another h? That is not exactly the same question. Its answer will surprise you and it is thought to be one motivating reason for the Gambler's fallacy.

Your program should run 5000 trials. For each trial, it should generate 100 coin tosses and store them in an array; using the array, you can compute for that trial how many runs of 'hhhh' are followed by a head, and the ratio of the two numbers. For example, the following trial contains 9 runs of 'hhhh' but only 3 of them are followed by another 'h', giving us a ratio of 0.33333333333

After the 5000 trials the program should print the average of the ratios. You should expect that the average should be about 0.41.

Experiment with your code and see what happens as the trials get shorter (eg, 20 coin tosses) or longer (1000 or more). In all cases, make sure you are running at least 5000 trials, so that the averages that you compute are meaningful. Additionally, you may explore a similar question, say, how often a 5th head is followed by yet another head. Other things to try might be a biased coin (eg, basketball players are not assumed to have a 50-50 chance to sink a basket, it varies) and the ratio of male/female babies, though pretty close to 1, varies a lot by species.

Sample output:

Trial #1 Count hhhh = 9

Count hhhhh = 6

ratio = 0.6666666666666666

Trial #2 Count hhhh = 2

Count hhhhh = 1

ratio = 0.5

Trial #3 Count hhhh = 3

Count hhhhh = 1

ratio = 0.3333333333333333

[ some output deleted here ]

Trial #4982

Count hhhh = 4

Count hhhhh = 1

ratio = 0.25

Trial #4983

Count hhhh = 2

Count hhhhh = 1

ratio = 0.5

Trial #4984

Count hhhh = 4

Count hhhhh = 1

ratio = 0.25

Trial #4985

Count hhhh = 2

Count hhhhh = 1

ratio = 0.5

Trial #4986

Count hhhh = 3

Count hhhhh = 1

ratio = 0.3333333333333333

Trial #4987

Count hhhh = 3

Count hhhhh = 1

ratio = 0.3333333333333333

Trial #4988 ***** did not produce any hhhh runs ****

Trial #4989

Count hhhh = 2

Count hhhhh = 0

ratio = 0.0

Trial #4990

Count hhhh = 3

Count hhhhh = 1

ratio = 0.3333333333333333

Trial #4991

Count hhhh = 3

Count hhhhh = 2

ratio = 0.6666666666666666

Trial #4992

Count hhhh = 4

Count hhhhh = 2

ratio = 0.5

Trial #4993

Count hhhh = 6

Count hhhhh = 3

ratio = 0.5

Trial #4994

Count hhhh = 7

Count hhhhh = 4

ratio = 0.5714285714285714

Trial #4995

Count hhhh = 7

Count hhhhh = 3

ratio = 0.42857142857142855

Trial #4996

Count hhhh = 9

Count hhhhh = 6

ratio = 0.6666666666666666

Trial #4997

Count hhhh = 6

Count hhhhh = 3

ratio = 0.5

Trial #4998

Count hhhh = 1

Count hhhhh = 0

ratio = 0.0

Trial #4999

Count hhhh = 3

Count hhhhh = 1

ratio = 0.3333333333333333

Trial #5000

Count hhhh = 4

Count hhhhh = 1

ratio = 0.25

Average ratio over 5000 runs: 0.4077585131619748

Style and Documentation

In addition to working well, your program should adhere to the general style and documentation guidelines expected(javadoc). This includes:

  • Appropriate
  • indentation and use of white space for readability. Make sure that matching braces are lined up on the same column and that statements that are
    • executed
    • conditionally (part of the if/else) are indented further.
    • Use
    • descriptive names for your variables.
    • Comments
    • should be used to document tricky parts and to explain the use of variables, where that is not obvious from their name.
    • Comments
    • should describe the overall goals of the program and give some details of its history, including when and by whom it was written, filename, when it was modified, its purpose, etc.
    • Avoid
    • long lines in the program: generally, no line of the program should be more than 80 characters long. This ensures that when you paste your program into
    • Word,
    • the lines will not be broken and it will still look the same as it looked on your screen.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!