Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java with comments, Complete the template provided to toss the coin 100 times and count the number of heads and the number of tails.

In Java with comments,

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

public class Lab2Num3 {

public static 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"; } } public static void main(String[] args) { Coin c= new Coin(); System.out.println(c); //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 } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions