Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Theoretically, it is known that a two-sided, equally weighted coin has a 50% cha

ID: 3552850 • 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.




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

( Properly indented and best one for you, with validation testing also done for invalid inputs using try/catch. )