ITEC 120 LAB 10 Back to Lab index page

Rock, Paper, Scissors game

You'll write a class called Player to simulate a person playing the game rock, paper, and scissors. The class will have one piece of instance data - a character, which will be 'R' for rock, 'P' for paper, and 'S' for scissors. (You may want to use some constants for this class, it's up to you.)

Player
- move : char

+ Player()
+ go() : void
+ getMove() : char
+ toString : String

The class wil have 4 methods:

The Player class will be somewhat similar to the Coin class (in the book).

Next, you will write a program to simulate two people playing the game of rock, paper, and scissors. Your program will instantiate two Player objects. Your program will ask the user how many times they want the players to play the game. Your program will then play the game that number of times, output the results of each game, and count the number of wins for player1, wins for player2, and the number of ties, and report all that at the end of the simulation.

For those who haven't played this game in a while, recall that rock smashes scissors, paper covers rock, and scissors cuts paper. Choose your own names for the players.

For example:

Program outputs: Sam and Sue are going to play Rock, Paper and Scissors.
How many times should they play?
User inputs: 6
Program outputs:

Game 1:     Sam: Rock       Sue: Paper     Sue WINS!
Game 2:     Sam: Paper      Sue: Paper     A TIE!
Game 3:     Sam: Rock       Sue: Scissors  Sam WINS!
Game 4:     Sam: Scissors   Sue: Paper     Sam WINS!
Game 5:     Sam: Paper      Sue: Scissors  SueWINS!
G
ame 6:     Sam: Scissors   Sue: Rock      Sue WINS!

Sue won 3 games.
Sam won 2 games.
There was 1 tie.

You will create two different files -- one for your Player class, and for your driver program (where the main method will be).

Use incremental design for this program. First, write the Player class. Get it to compile (you can't run it by itself, but you can compile it). Then, write a driver program which instantiates 2 Player objects. Have them play one game and output the result of that game (using toString). Get that to run.

Then, put your loop in. Ask the user how many games, and have your program play the game that number of times. After that works, then add in the logic to figure out who won each game, count the wins for each player, and the number of ties, and output the results.

Once you have your program working, show your lab to the Peer Instructor to be checked off.