Lab 2 –Rock, Paper, Scissors
For this lab, you will be implementing the game of Rock, Paper, Scissors. For those unfamiliar with the rules, typically the game is played with two people who use hand gestures to represent a rock (closed fist), paper (an open hand), or scissor (a vee made with your fingers.) Each person displays their choice at the same time and the winner is determined by (winner in bold):
Scissors cut paper, paper covers rock, rock breaks scissors
Your job will be to write a program where a human can play against the computer. Have the human player enter their choice, and then have the computer randomly pick its choice. If the two match, the game is a tie.
Welcome to Rock, Paper, Scissors
What is your choice?
1.) Rock
2.) Paper
3.) Scissors
What is your choice? 3
The computer chooses rock. You lose!
We haven’t covered handling user input in lecture yet, but here is a snippet of code you can use to read in a single integer from the user and store it in choice:
java.util.Scanner input = new java.util.Scanner(System.in);
int choice = input.nextInt();
That’s verbose even by Java’s standards, but that is because we have some additional things to talk about before we can make that code shorter.
When you are done, submit via the website. The instructions can be found in Lab 1 on the class website.
If for some reason you do not finish in the allotted class time, it is due before the start of your next lab.