Using the Coin Class
This lab gives you practice with writing and calling simple
methods. It also gives you practice with using methods to access private data
members.
The code for a Coin class is in the file Coin.java.
Copy it to your directory, then write a program to find the length of the longest
run of heads in 100 flips of the coin. A skeleton of the program is in the file
Runs.java. To use the Coin class you need to do the
following in the program:
- Create a coin object.
- Inside the loop, you should use the flip method
to flip the coin, the toString method (used implicitly) to print the
results of the flip, and the getFace method to see if the result was
HEADS. Keeping track of the current run length (the number of times in a row
that the coin was HEADS) and the maximum run length is an exercise in loop
techniques!
- Print the result after the loop.

Go back to lab1 index
page