Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5.26 Rock,Paper,Scissors is a two-player game in which each player chooses one o

ID: 3920661 • Letter: 5

Question

5.26 Rock,Paper,Scissors is a two-player game in which each player chooses one of three items. If both players choose the same item, the game is tied. Otherwise, the rules that determine the winner are: (a) Rock always beats Scissors(Rock crushes Scissors) (b) Scissors always beats Paper(Scissors cut Paper) (c) Paper always beats Rock(Paper covers Rock) Implement function rps() that takes the choice ('R', 'P', or 'S') of player 1 and the choice of player2, and returns?1 if player1 wins,1 if player2 wins,or 0 if there is a tie.

Explanation / Answer

Here is the java code rps function implemented according to the rules defined in the question

For full code with driver main function see below

Sample outputs

R

R

0

Sample output 2

R

P

1

For any further queries please comment and I will try to solve

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote