Add |
Add the following methods to While class:
- Write a method, coinFlip, that uses a while loop to "flip" a
coin 6 times. In the while loop generate a random number (int) in
the range 0, 1. If the number generated is odd, display "heads" in
the terminal window, otherwise display "tails". Invoke the method
several times and keep a (mental) count of the number of times
heads and tails occur each time. Although the counts you observe
vary each time the method is run, what total result would you
expect to see after invoking the method hundreds of times?
- Write a method, willItQuit(), that uses a while loop to
generate and display random numbers in the range 1 to 100 until the
number generated is greater than 50. Run your method several times
and observe the results. Assuming your loop to have the correct
logic, what would you conclude about the random number generator if
the while loop never terminated on a particular run?
- Write a method, windowPos(), that uses a while loop to display
five random (xPosition, yPosition) pairs in the ranges
0...myCanvas.getWidth() and 0...myCanvas.getHeight(),
respectively.
|