Theoretically, it is known that a two-sided, equally weighted coin has a 50% cha
ID: 3552531 • Letter: T
Question
Theoretically, it is known that a two-sided, equally weighted coin has a 50% chance of landing on heads and a 50% chance of landing on tails. However, is this really what happens in practice? For example, if you took a penny and flipped it 100 times, would it always produce heads 50 times and tails 50 times? Instead of actually flipping a coin, you will be simulating coin flips to find out how often heads and tails appear. Make heads to be a constant assigned to 1 and tails to be a constant assigned to 2. (For fun, you can also flip an actual coin!)
Phase I - Flip a Coin.
Your program should implement the following methods with partial signatures:
/** getNum method will prompt the user for a whole number and return a positive integer > 0. **/ /** The message for prompting is given by msg. **/ /** In case of invalid input, it will display errorMsg. **/ /** Make sure you validate that the input entered is both a number and a positive integer. **/ /** If the user enter invalid input, your program should show an error message and keep asking. **/ /** (Your program should not stop if the input is invalid!) **/ /** Sample call: int coins = getNum(
Explanation / Answer
The 51% figure in Premise 1 is a bit curious and, when I first saw it, I assumed it was a minor bias introduced by the fact that the "heads" side of the coin has more decoration than the "tails" side, making it heavier. But it turns out that this sort of imbalance has virtually no effect unless you spin the coin on its edge, in which case you'll see a huge bias. The reason a typical coin toss is 51-49 and not 50-50 has nothing to do with the asymmetry of the coin and everything to do with the aggregate amount of time the coin spends in each state, as it flips through space.
A good way of thinking about this is by looking at the ratio of odd numbers to even numbers when you start counting from 1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
No matter how long you count, you'll find that at any given point, one of two things will be true:
What will never happen, is this:
Similarly, consider a coin, launched in the "heads" position, flipping heads over tails through the ether:
At any given point in time, either the coin will have spent equal time in the Heads and Tails states, or it will have spent more time in the Heads state. In the aggregate, it's slightly more likely that the coin shows Heads at a given point in time
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.