Question: In java : Complete the template provided to toss the coin 100 times and count the number of heads and the number of tails. public

In java : Complete the template provided to toss the coin 100 times and count the number of heads and the number of tails.

public class Lab3Num1 {

public static void main(String[] args) { Coin c= new Coin(); //complete this program by adding code to flip the coin 100 times //counting the number of heads and the number of tails //SHOW ME your solution. IT WILL NOT be accurate according to zybooks //because of the randomness System.out.println("The number of heads is " + count + " and the number of tails is " + (100-count)); } }

public class Coin { private int face; //heads is 0, tails is 1 // constructor sets up coin by flipping it initially public Coin() { //constructor flips the coin to determine whether // the face is heads or tails flip(); } public void flip() { //returns 0 or 1 face=(int) (Math.random()*2); } public boolean isHead() { return (face==0); } public String toString() { //this method allows us to print the value of a coin if (face==0)return "Heads"; else return "Tails"; } }

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!