Rock Paper Scissors Lab
ROCK PAPER SCISSORS LAB
Create a new Java project in Intellij or add these file to your Lab Set A&B Project.
Lab Directions:
1. Create RandomPlayer and PlayerRunner.
2. RandomPlayer will have the following instance variables:
a. name - stores player’s name
b. wins - stores the number of wins
c. choice – stores the current value being played
3. You need to create a RandomPlayer constructor that receives a name parameter, sets wins to 0,
and sets choice to "none".
4. RandomPlayer will have the following methods.
a. String getName( ) - returns the name of the player
b. String getChoice( ) - returns the choice that will be played
c. int getWins() - returns number of wins
d. void addAWin( ) - add 1 to wins
e. void resetWins( ) - reset wins to 0
f. void pick( String[] things ) – sets choice to a random value from things
g. String toString() - returns a string containing the player’s name and wins
5. Add code to PlayerRunner to test your RandomPlayer class.
//runner test code
RandomPlayer a = new RandomPlayer("bob");
[Link]( [Link]() ); //outs bob
[Link]( [Link]() ); //outs 0
[Link]();
[Link]();
[Link]( [Link]() ); //outs 2
[Link]();
[Link]( [Link]() ); //outs 0
String[] options = "R P S".split(" "); //could be any values
[Link]( options );
[Link]( [Link]() ); //outs R, P, or S
Computer Science II K
Rock Paper Scissors Lab
6. Create [Link]
a. At the top of the [Link] file, import [Link];
7. In the RPSRunner, you will need two RandomPlayer variables and 1 Scanner. These variables will
go in the main method of the RPSRunner class. There are NOT instance variables.
a. RandomPlayer player1
b. RandomPlayer player2
c. Scanner kb
8. In the main method, write code that uses a for loop to play a game of 5 rounds.
a. Print out what each player is playing for each round.
b. Print out which player wins each round.
c. A tie should not count as a win for either player.
d. Print out the score for both players after each round.
e. Print out the final score for each player after the game of 5 rounds.
9. In the main method, add in Scanner input.
a. Remove the for loop that played a game of 5 rounds.
b. Use a while or do while loop to allow players to play RPS.
c. Use Scanner and keyboard input to allow the players to decide if they want to keep playing
after each round.
d. Players can play as many rounds as they want.
e. Replay the round for ties.
Computer Science II K