I have a program that randomly flips a quarter 100 times. The results gives me a list of heads and tails. I need the results to look like this:
100 Flips resulted in 49 heads and 51 tails. With varing numbers for heads and tails.

Thank you for any help given.

I have two sets of Classes the first is FlipResult and the second is Driver. Here they are:

//FlipResult Class
 
import java.awt.BufferCapabilities.FlipContents;

public class FlipResult {

Quarter quarter;

public FlipResult(){

quarter = new Quarter();

} 

public void run(){

for(int j = 0; j < 100; j++){

quarter.flip();

System.out.println(quarter.isHeads()? "heads" : "tails");

}

}

}

//Driver Class

public class Driver {

public static void main(String[] args) {

System.out.println("100 flips resulted in" );


FlipResult tf = new FlipResult(); 

tf.run();

}

}

You may want to keep results of each flip in a collection(array, vector, list). Then ad the end you call a method to get print of how many heads and tails and forward this collection as argument for method. To get numbers, create another method that will get collection as parameter and also second parameter (heads || tails) and base on that prints position numbers where second parameter equals with entry in collection.

Try to code it, if you get in difficulties then ask

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.