rockPaperScissors

Category: Programming
Author: Marty Stepp and Ruth Anderson
Book Chapter: 4.1
Problem: rockPaperScissors
Write a static method named rockPaperScissors that accepts a pair of integers as parameters representing two players' choices in the game of Rock-Paper-Scissors, and returns which player won the game.

Rock-Paper-Scissors is an old game where two people each simultaneously choose one of three possible weapons: a rock, a piece of paper, or a pair of scissors. The paper defeats the rock but loses to the scissors. The rock defeats the scissors but loses to the paper. The scissors defeats the paper but loses to the rock. If the two players choose the same weapon, the game is a tie.

In your code, the two players' weapons are passed as integer parameters. Paper is represented as the integer value 0, rock is represented as 1, and scissors is represented as 2. Your method should examine the two players' weapons and return an integer representing the player that won the game. If the first player wins the game, return 1. If the second player wins the game, return 2. Your method should return 0 in the case of a tie. You may assume that both parameter values passed will be valid (between 0 and 2 inclusive).

Call                    | Meaning                     | Value Returned
-----------------------------------------------------------------------
rockPaperScissors(0, 1) | p1 is paper, p2 is rock     | 1
rockPaperScissors(2, 1) | p1 is scissors, p2 is rock  | 2
rockPaperScissors(0, 0) | p1 is paper, p2 is paper    | 0
rockPaperScissors(1, 2) | p1 is rock, p2 is scissors  | 1
rockPaperScissors(1, 1) | p1 is rock, p2 is paper     | 2