flip

Category: Programming
Author: Stuart Reges
Book Chapter: 5.1
Problem: flip
  Write a method flip that takes a Random object as a
   parameter and that prints information about a coin-flipping simulation.

   Your method should use the Random object to produce a sequence of simulated
   coin flips, printing whether each flip comes up "heads" or "tails".  Each
   outcome should be equally likely.  Your method should stop flipping when you
   see three heads in a row.  It should return the total number of flips.

   For example, if we construct a Random object and make the following calls;

        Random r = new Random();
        flip(r);
        flip(r);

   We expect to get a log of execution like this:

        heads
        tails
        heads
        heads
        heads
        3 heads in a row after 5 flips
        
        heads
        heads
        tails
	heads
	tails
	tails
        heads
        heads
        heads
        3 heads in a row after 9 flips
        
   You must exactly reproduce the format of the log above.

   Write your solution to flip below.