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

I have to write a code based on the question, but I have no idea how to write it

ID: 3879665 • Letter: I

Question

I have to write a code based on the question, but I have no idea how to write it. EXERCISE In this problem, you will write a method that takes in two Strings representing a round of "rock, paper, scissors." The Strings entered for the user and the computer will be "rock""paper", or "scissors". The method should return a String representing who the winner is provided by the three String variables USER PLAYER, COMPUTER PLAYER, and TIE. For example, if the user plays "rock" and the computer plays "scissors". the user wins.

Explanation / Answer

I have Written the code for game in java.I have implemented the same method given by you.

Code:

public static void Main(string[] args)
{
//random number geberator
Random random=new Random();
//scanner object for input
Scanner scanner=new Scanner();
  
/*Interger value to hold the computer and user choice
*
* 0-Rock
* 1-Paper
* 2-Scissors
*/
int userChoice,computerChoice;

//Showing prompt and user input
System.out.println("Enter move (0=rock; 1=paper; 2=Scissors)");
userChoice=scanner.nextInt();

//Checking if userChoice is 0,1 and 2
if(userChoice<0 || userChoice>2)
{
System.out.println("Invalid choice.Ending program");
System.exit(0);
}
//Generation random computer choice
computerChoice=random.nextInt(3);
System.out.println(getWinner(userChoice,computerChoice));

}

private String getWinner(int userChoice,int computerChoice)
{
String USER_PLAYER="User wins!!";
String COMPUTER_PLAYERS="cOMPUTER WINS!!!";
String TIE="Tie";
//If the choice are equal,It's tie
if(userChoice==computerChoice)
{
if(userChoice==0)
{
return TIE;
}
else if(userChoice==1)
{
return TIE;
}
else
{
return TIE;
}

System.exit(0);
}

//User choose rock
if(userChoice==0)
{
if(computerChoice==1)
{
return COMPUTER_PLAYERS;
}
else
{
return USER_PLAYER;
}
}
else if(userChoice==1)
{
if(computerChoice==0)
{
return USER_PLAYER;
}
else
{
return COMPUTER_PLAYERS;
}
}
else
{
if(computerChoice==0)
{
return COMPUTER_PLAYERS;
}
else
{
Sreturn USER_PLAYER;
}
}
scanner.close();

}

Thanks