Question: import java.util.*; /******************************************************** * A Simulated Coin * *******************************************************/ public class GVcoin{ // true for heads, false for tails private boolean isHeads; private int flips,

import java.util.*; /******************************************************** * A Simulated Coin * *******************************************************/ public class GVcoin{ // true for heads, false for tails private boolean isHeads; private int flips, heads; private Random r;
/*************************************************** Create the coin ***************************************************/ public GVcoin(){ r = new Random(); heads = 0; flips = 0; isHeads = true; } /*************************************************** Flip the coin by random choosing true / false ***************************************************/ public void flip(){ isHeads = r.nextBoolean(); flips++; if(isHeads){ heads++; } } /*************************************************** @return true if coin is currently heads ***************************************************/ public boolean isHeads(){ return isHeads; } /*************************************************** @return String representation of important values ***************************************************/ public String toString(){ String str; str = "Flips: " + flips + " Heads: " + heads + " isHeads: " + isHeads; return str; } /*************************************************** @return number of total flips ***************************************************/ public int numFlips(){ return flips; } /*************************************************** @return number of total heads ***************************************************/ public int numHeads(){ return heads; } /*************************************************** @return number of total tails ***************************************************/ public int numTails(){ return flips - heads; } /*************************************************** Set the coin to heads (or tails) to start ***************************************************/ public void setToHeads(boolean h){ isHeads = h; }
/*************************************************** Create the coin with a random seed ***************************************************/ public GVcoin(int seed){ this(); r = new Random(seed); }
}
Complete the following method that is passed a GVcoin and the number of desired consecutive heads without a tail. Return how many fips it takes to record that many consecutive heads. LAB ACTITY 7.17.1: zyLab: Consecutive heads 0/2 Current file. TossingCoins.java Load default template... 1 public class TossingCoins 3 public int consecutiveHeads (GVcoin c, int goal)f 4 * Type your code here. / 8 IThis method creates a TossingCoins object and calls the method for testing 9 public static void main(String[] args) f TossingCoins game new TossingCoins(); GVcoin c new GVcoin); int flips game . consecutiveHeads(c, 5); 12 13 14
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
