Assignment4C Heads or Tails? It is said that a perfectly fair coin will return heads 50% of the time, and tails 50% of the time. Rather than have you test this theory by flipping a coin yourself, let's use a random number generator and loops to determine the truth. Create a program that prompts the user for a number of coin flips. Then, “flip a coin" that many times by using a random number generator that produces either a 0 or 1. Afterwards, show the user how many times it landed on heads (0) and tails (1) and calculate the frequency for each. Inform the user if heads or tails was the more frequency result, or if they were equal. Call the file name Assignment4C (.java, .cs, .cpp) and the class name Assignment4C. Example outputs are shown below. Note that due to using a random number generator, you may not get the same numerical results – but the formatting and wording should be the same. User input is indicated in bold. Sample Output #1: How many times do you want to flip the coin?: 100 After flipping the coin 100 time(s), we found that it lands on: Heads - 51 times (0.51%) Tails 49 times (0.49%) The coin lands on heads more often than tails! Sample Output #2: How many times do you want to flip the coin?: 1000 After flipping the coin 1000 time(s), we found that it lands on: Heads - 498 times (0.498%) Tails - 502 times (0.502%) The coin lands on tails more often than heads! Sample Output #3: How many times do you want to flip the coin?: 50 After flipping the coin 50 time(s), we found that it lands on: Heads - 25 times (0.5%) Tails - 25 times (0.5%) The coin is perfectly fair!
Assignment4C Heads or Tails? It is said that a perfectly fair coin will return heads 50% of the time, and tails 50% of the time. Rather than have you test this theory by flipping a coin yourself, let's use a random number generator and loops to determine the truth. Create a program that prompts the user for a number of coin flips. Then, “flip a coin" that many times by using a random number generator that produces either a 0 or 1. Afterwards, show the user how many times it landed on heads (0) and tails (1) and calculate the frequency for each. Inform the user if heads or tails was the more frequency result, or if they were equal. Call the file name Assignment4C (.java, .cs, .cpp) and the class name Assignment4C. Example outputs are shown below. Note that due to using a random number generator, you may not get the same numerical results – but the formatting and wording should be the same. User input is indicated in bold. Sample Output #1: How many times do you want to flip the coin?: 100 After flipping the coin 100 time(s), we found that it lands on: Heads - 51 times (0.51%) Tails 49 times (0.49%) The coin lands on heads more often than tails! Sample Output #2: How many times do you want to flip the coin?: 1000 After flipping the coin 1000 time(s), we found that it lands on: Heads - 498 times (0.498%) Tails - 502 times (0.502%) The coin lands on tails more often than heads! Sample Output #3: How many times do you want to flip the coin?: 50 After flipping the coin 50 time(s), we found that it lands on: Heads - 25 times (0.5%) Tails - 25 times (0.5%) The coin is perfectly fair!
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education