Question
Write a java program which simulates the toss of a coin. Whenever a coin is tossed the result will be either a head or tail.
Write a java program which simulates the toss of a coin. Whenever a coin is tossed the result will be either a head or tail. Prompt the user as shown by entering a H for heads or T for tails. Use a loop for input validation of an h or t. Make sure that both an upper case and lower case will be accepted. Have the computer generate a random number. Assign a char variable a head or tail so that the probability of either is equally possible. Display the outcome of the coin toss using a window, either You Win! or Computer Wins as a result of the users guess compared to the random number generated. Use a loop for multiple flips of the coin. The user enters either Y or y to continue the program. Keep track of the number of wins and losses. Display the summary when the user decides to quits the program.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started