## Assignment 10

Write a very simple rock-paper-scissors (aka, jan-ken-pon) game. (This program will be the basis of our second studio.)

Concepts: Review of conditionals, Strings, random numbers, methods.

### Steps

• Ask the user to enter a move, either as a string or as an int. You can have them enter one of the words "rock", "paper", or "scissors". Sample prompt:

Enter your move (rock, paper, or scissors):

Or you can instead print a short menu explaining how the numbers 1, 2 and 3 map to "rock", "paper", or "scissors", and then ask them to enter the corresponding number. Something like this would work (though you could possibly do it clearly in a single line instead). Sample menu prompt:

1) Rock
2) Paper
3) Scissors
Enter the number of your move:
• Once you have the player's move, generate a random move for the computer, and print it (as "rock", "paper", or "scissors", not as a number) on its own line. Sample:
Computer's move: paper

• Then determine and display who won on another line. The rules are simple: paper beats rock, rock beats scissors, scissors beats paper. If the two moves are the same (for example, both rocks) then the game is a tie.

When displaying output, you may refer to the computer as "computer", "PC", "I", or "my". You may refer to the player as "player", "user", "human", or "you". (Case does not matter.) Print who "won" or "wins", or print that the game is a "tie" or "draw". Three sample outcomes:

You won!

Computer won!

Game was a tie.

The game should only play one round and then quit.

Your program must include at least one static method in addition to main.

### Hints

• You're probably going to have to generate a random number to get the computer's random move. Generate an int between 1 and 3 (or 0 and 2, if you prefer), and then translate it to a String for printing.
• To compare the player's move to that of the computer, it's probably best to translate both moves to numbers or both to Strings.
• You must write at least one additional method, but you may write more than one if you like. Good candidates for methods include: generating a random move for the computer, translating a move from a number to a String (or vice-versa), or determining who won from two given moves.

### What to Submit

Upload your UsernameA10a.java file to Tamarin. (This program will serve as the basis of our second studio.)

To resubmit after the studio, upload your UsernameA10b.java file to Tamarin

### Grading [10 points]

1 - Compiles
Your program compiles successfully (no errors)
2 - Input
Your user interface (UI) is clear on what input is required (format, range, etc) (0.5). Valid input is either (1, 2 or 3) or ("rock", "paper", or "scissors") (1.0). Program ends gracefully if input is invalid in any way (0.5).
2 - Computer move
Computer's move is random (1.0). Computer's move is printed and labelled using one of the allowed terms described above (1.0).
3 - Result
You correctly print who won/wins, or that the game is a tie/draw.
2 - Method
You have at least one more method beyond main (that you actually call from within main).

### FAQs

 ~ztomasze Index : TA Details: ICS111: A10 http://www2.hawaii.edu/~ztomasze Last Edited: 28 Sep 2008 ©2008 by Z. Tomaszewski.