Question: Modifying the Coin Class Create a new class named BiasedCoin that models a biased coin ( heads and tails are not equally likely outcomes of
Modifying the Coin Class
Create a new class named BiasedCoin that models a biased coin heads and tails are not equally likely outcomes of a flip To do this modify the coin class from the text in the file Coin.java below as follows:
a Add a private data member bias of type double. This data member will be a number between and inclusive that represents the probability the coin will be HEADS when flipped. So if bias is the coin is an ordinary fair coin. If bias is the coin has probability of coming up heads on average, it comes up heads of the time
b Modify the default constructor by assign g the value to bias before the call to flip. This will make the default coin a fair one.
c Modify flip so that it generates a random number then assigns face a value of HEADS if the number is less than the bias; otherwise it assigns a value of TAILS.
d Add a second constructor with a single double parameter that parameter will be the bias. If the parameter is valid a number between and inclusive the constructor should assign the bias data member the value of the parameter; otherwise it should assign bias a value of Call flip as the other constructor does to initialize the value of face.
Compile your class to make sure you have no syntax errors.
Write a program that uses three BiasedCoin objects. Instantiate one as a fair coin using the constructor with no parameter. Read in the biases for the other two coins and instantiate those coins using the constructor with the bias as a parameter. Your program should then have a loop that flips each coin times and counts the number of times each is heads. After the loop print the number of heads for each coin. Run the program several times testing out different biases.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
