Write a program to simulate flipping 100 coins

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Write a program to simulate flipping 100 coins. Print out the result of every flip (either Heads or Tails).

At the end of the program, print out how many heads you flipped, how many tails you flipped, what percentage were heads, and what percentage were tails. 

use java

4.3.5: Coin Flips
1 þublic class CoinFlips extends ConsoleProgram
2- {
public static final int FLIPS = 100;
3
4
5-
public void run() {
}
8 }
7
Transcribed Image Text:4.3.5: Coin Flips 1 þublic class CoinFlips extends ConsoleProgram 2- { public static final int FLIPS = 100; 3 4 5- public void run() { } 8 } 7
4.3.5: Coin Flips
1 import java.util.*;
2- public class Randomizer{
public static Random theInstance = null;
public Randomizer(){
}
public static Random getInstance(){
if(theInstance == null){
3
5
6 -
7
8
theInstance = new Random();
}
return theInstance;
}
public static boolean nextBoolean(){
return Randomizer.getInstance().nextBoolean();
}
public static boolean nextBoolean(double probability){
return Randomizer.nextDouble() < probability;
}
9
10
11
12 -
13
14
15
16
17
18
public static int nextInt(){
return Randomizer.getInstance().nextInt();
}
public static int nextInt(int n){
return Randomizer.getInstance().nextInt(n);
}
public static int nextInt(int min, int max){
return min + Randomizer.nextInt(max - min + 1);
}
public static double nextDouble(){
return Randomizer.getInstance().nextDouble();
}
public static double nextDouble(double min, double max){
return min + (max - min) * Randomizer.nextDouble();
}
19 -
20
21
22 -
23
24
25 -
26
27
28
29
30
31 -
32
33
34 }
35
Transcribed Image Text:4.3.5: Coin Flips 1 import java.util.*; 2- public class Randomizer{ public static Random theInstance = null; public Randomizer(){ } public static Random getInstance(){ if(theInstance == null){ 3 5 6 - 7 8 theInstance = new Random(); } return theInstance; } public static boolean nextBoolean(){ return Randomizer.getInstance().nextBoolean(); } public static boolean nextBoolean(double probability){ return Randomizer.nextDouble() < probability; } 9 10 11 12 - 13 14 15 16 17 18 public static int nextInt(){ return Randomizer.getInstance().nextInt(); } public static int nextInt(int n){ return Randomizer.getInstance().nextInt(n); } public static int nextInt(int min, int max){ return min + Randomizer.nextInt(max - min + 1); } public static double nextDouble(){ return Randomizer.getInstance().nextDouble(); } public static double nextDouble(double min, double max){ return min + (max - min) * Randomizer.nextDouble(); } 19 - 20 21 22 - 23 24 25 - 26 27 28 29 30 31 - 32 33 34 } 35
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY