Question: You are given the file Coin.java, which contains the Coin class from your textbook and which you should not modify for this exercise. Complete the
You are given the file Coin.java, which contains the Coin class from your textbook and which you should not modify for this exercise.
Complete the driver program in Bingo.java by adding code where indicated, in order to obtain a program that flips a coin 20 times and displays the results. The program should also display the word BINGO! whenever it gets a run of three Heads in a row, as in the example below. Note that each Heads should count towards a single BINGO!, so six Heads in a row should give only two BINGO!'s.
Inside the for loop, you should use the flip method to flip the coin, the toString method to display the result of the flip, and the isHeads method to check if the result was Heads or not.
Submit your completed Bingo.java file.
public class Bingo {
public static void main(String[] args) {
final int FLIPS = 20; // Number of coin flips
int run = 0; // length of the current run of Heads (up to 3)
// **COMPLETE CODE to create a Coin object
for (int i = 0; i < FLIPS; i++) { // Flip the coin FLIPS times
// **COMPLETE CODE to flip the coin and print the result
// **COMPLETE CODE to update the current run and print BINGO! if necessary.
// Hint: Increment run if you got Heads. If it reaches 3, reset to 0.
// Also reset to 0 if you got Tails.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
