Write a program RockPaperScissors.java
that allows the user to play the game of Rock, Paper, Scissors with the computer (Rock crushes Scissors, Scissors cut Paper, Paper covers Rock).
As part of this program, write a method getWinner(String player1, String player2)
which will determine who the winner is.
Given that player1
is a String
variable that has the value “rock”, “paper”, or “scissors”, and that player2
is a String
variable that holds one of the three same values, write a set of if-else
statements that will return the integer 1
if player1
wins, 2
if player2
wins, and 0
if it’s a tie.
In the main()
program, have the user enter their choice–“rock”, “paper”, or “scissors”–and then have the computer randomly determine its choice. Call the method getWinner(String player1, String player2)
to determine who the winner is.