Write a simple rock-paper-scissors (aka, jan-ken-pon) game that plays only a single round.
Concepts: Review of conditionals, Strings, random numbers, methods.
• 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:
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:
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
- 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 the corresponding 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
UsernameA09.java file to Tamarin.
Grading [10 points]
- 1 - Compiles
- Your program compiles successfully (no errors) and follows Java coding standards.
- 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 and evenly distributed (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
- This question usually isn't asked, but based on past experience, I'd recommend you double-check these things before submitting:
- Remember that you have to use
.equalsIgnoreCase to compare Strings
- The words "lose" and "lost" will never appear in your output, because you always say who won instead.
- Watch your spelling, both in output and in matching input. ("Scissors" is particularly easy to misspell.)
- Make sure your program really generates the full range of possible moves for the computer.