Lab 7

Random numbers and the Switch Statement: Review chapter 4 before beginning.

In order to get any credit, you must create a typescript file with your listing, compilation and execution and email it to your TA.
Click here for help making a typescript.

This exercise will have you practice using random numbers and the switch statement. Random numbers are at the heart of most games and can be used to improve user interfaces. The switch statement is used to evaluate a series of choices. (Note on switch: switch only works with ints and chars and you must add a break statement after each case to prevent execution from continuing to the the next statement.) To practice these, we are going to have you implement the "Rock-Scissors-Paper" game. While there are many ways to write this, you must follow the instructions below for credit, so we can be sure you have practiced the necessary concepts. If you have never played this game, here are the rules: Each player chooses one of the following: 1) Rock, 2) Scissors, or 3) Paper. Then their choices are compared to determine the winner.

Rock beats Scissors. (1 beats 2)
Scissors cuts Paper. (2 beats 3)
Paper wraps Rock. (3 beats 1)
Create an int function that returns a random number between 1 and 3. This value is the computer's pick. See the program: guessgame.java for an example of random number generation.
Algorithm for the main method:
Your main method will contain a do..while loop that continues until the user wants to quit.
    Generate the computer's pick
    Get the user's guess
    If the user does not want to quit, then
      If it is not a tie game, then
      Evaluate the user's guess with a switch statement
          There will be cases 1,2,3, and a default that handles erroneous input (hint: each case will have 
	an if..else statement)
Sample Execution

>java rockscissorspaper
Welcome to the Rock Scissors Paper Game!

Enter in 1 for Rock, 2 for Scissors, 3 for Paper, or 0 to quit:
2
You win! Scissors cuts paper!

Enter in 1 for Rock, 2 for Scissors, 3 for Paper, or 0 to quit:
1
Tie Game!!

Enter in 1 for Rock, 2 for Scissors, 3 for Paper, or 0 to quit:
2
You win! Scissors cuts paper!

Enter in 1 for Rock, 2 for Scissors, 3 for Paper, or 0 to quit:
1
You win!  Rock beats Scissors!

Enter in 1 for Rock, 2 for Scissors, 3 for Paper, or 0 to quit:
3
Tie Game!!

Enter in 1 for Rock, 2 for Scissors, 3 for Paper, or 0 to quit:
4
Invalid Entry, try again!

Enter in 1 for Rock, 2 for Scissors, 3 for Paper, or 0 to quit:
0
Thanks for playing! Bye!