Question: 1. Create a new class named Coin that models a biased coin (heads and tails are not equally likely outcomes of a flip).To do this

1. Create a new class named Coin that models a biased coin (heads and tails are not equally likely outcomes of a flip).To do this modify the provided coin class Coin.java as follows: Add a private data member bias of type double. This data member will be a number between 0 and 1 (inclusive) thatrepresents the probability the coin will be HEADS when flipped. So, if bias is 0.5, the coin is an ordinary fair coin.If bias is 0.6, the coin has probability 0.6 of coming up heads (on average, it comes up heads 60% of the time). Modify the default constructor by assigning the value 0.5 to bias before the call to flip. This will make the default

coin a fair one. Modify flip so that it generates a random number then assigns face a value of HEADS if the number is less than thebias; otherwise it assigns a value of TAILS. Add a second constructor with a single double parameterthat parameter will be the bias. If the parameter is valid(a number between 0 and 1 inclusive) the constructor should assign the bias data member the value of the parameter;otherwise it should assign bias a value of 0.5. Call flip (as the other constructor does) to initialize the value of face.

2. Compile your class to make sure you have no syntax errors. 3. Write a test program TestBiasedCoins.java that uses three Coin objects. Instantiate one as a fair coin using theconstructor with no parameter. Read in the biases for the other two coins and instantiate those coins using the constructorwith the bias as a parameter. Your program should then have a loop that flips each coin 100 times and counts the numberof times each is heads. After the loop print the number of heads for each coin. Run the program several times testing outdifferent biases.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!