Exercise: Rock Paper Scissors
Write a console program that plays a single round of the game "rock paper scissors". The program should:
- Ask the user to choose between Rock, Paper, and Scissors.
- Randomly choose Rock, Paper, or Scissors for the computer.
- Print the user's choice and the computer's choice.
- Print the result of the round (e.g., "You win!", "You lose!", or "It's a tie!").
For example (user input in green):
Choose between Rock, Paper, and Scissors:
Rock
You chose Rock. CPU chose: Scissors
You win!
Thanks for playing!
You can use Wikipedia to remind yourself of the rules of Rock Paper Scissors.
Hint 💡
Use the
equals
method to compare strings. For example:
if (userChoice.equals("Rock")) {
// Do something
}
Hand in instructions
- Make sure your program runs correctly.
- Hand in your program by uploading Main.java to Moodle.