ITEC 120 LAB 9 | Back to Lab index page |
Coin Toss game
You will write Java program that will simulate a coin toss game between 3 people. Each person flips a coin. If all three coins are the same (all heads or all tails) then everyone keeps their coins and flips again. If two coins are the same and one is different, then the person with the different coin wins the game. Your program will count each person's wins and the number of ties.
You will use the Coin class for this program (download it), and you'll write a driver program which will instantiate 3 Coins. The logic in the driver program is easier to implement if you have a getValue() method in the Coin class, so add that method to the existing Coin class. The getValue() method returns an int, the value of the instance data face.
Sample run:
Program outputs: | Let's
play a coin toss game! Please enter player 1: |
User inputs: | Sue |
Program outputs: | Please enter player 2: |
User inputs: | Bob |
Program outputs: | Please enter player 3: |
User inputs: | Sam |
Program outputs: | How many tosses? |
User inputs: | 7 |
Program outputs: | Sue: Tails
Bob: Heads Sam: Heads Sue wins! Sue: Heads Bob: Tails Sam: Heads Bob wins! Sue: Tails Bob: Heads Sam: Tails Bob wins! Sue: Tails Bob: Tails Sam: Heads Sam wins! Sue: Heads Bob: Tails Sam: Heads Bob wins! Sue: Heads Bob: Tails Sam: Heads Bob wins! Sue: Tails Bob: Tails Sam: Heads Sam wins! ---------------------------------------------- Sue won 1 game. Bob won 4 games. Sam won 2 games. There were 0 ties. |
Once you have your program working, show your lab to the Peer Instructor to be checked off.