Rock, Paper, Scissors is a hand game played by two people. Both people would say "rock, paper, scissors" and then simultaneously form one of three objects (rock, paper, or scissors) with an outstretched hand. The winner is determined by the hand formations. Scissors beats paper, paper beats rock, and rock beats scissors. If both players play the same hand formation, it is considered a tie. We will write a simple game in Java to simulates Rock, Paper, Scissors where one player is the user and the other player is the computer.
Remember! to read input from standard device (in this case is keyboard), use class Scanner.
import java.util.Scanner;
public class RockPaperScissors
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Player 1: Choose rock, scissors, or paper:");
String player1 = scan.next().toLowerCase();
System.out.println("Player 2: Choose rock, scissors, or paper:");
String player2 = scan.next().toLowerCase();
if (player1.equals(player2))
{
System.out.print("It is a tie");
}
}
}
Try run the program and see the output.
Complete the program. Remember, the second player is a computer (Hint: Use method random).