Question

In: Computer Science

In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper,...

In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows:

• Rock beats scissors, because a rock can break a pair of scissors.
• Scissors beats paper, because scissors can cut paper.
• Paper beats rock, because a piece of paper can cover a rock.

Create a game in which the computer randomly (hint: Math.random()) chooses rock, paper, or scissors. Let the user enter "rock", "paper" or "scissor". Then, determine the winner.

Save the application as RockPaperScissors.java.

Solutions

Expert Solution

input code:

output:

code:

import java.util.*;
public class RockPaperScissors
{
   public static void main(String[] args)
   {
   Scanner s=new Scanner(System.in);
   Random r=new Random();
   /*print the menu*/
System.out.println("\n");
System.out.println("ROCK PAPER SCISSORS MENU");
System.out.println("1. Rock");
System.out.println("2. Paper");
System.out.print("3. Scissor\nEnter your choice:");
       /*take input*/
String userChoice=s.next();
/*generate number*/
int computerChoice = r.nextInt() % 3 + 1;
/*check computerChoice and display according to it*/
if (computerChoice == 1)
{
/*if computerChoice==1 than print this*/
System.out.println( "Computer: Rock");
}
else if (computerChoice == 2)
{
/*if computerChoice==2 than print this*/
System.out.println( "Computer : Paper");
}
else if (computerChoice == 3)
{
/*if computerChoice==3 than print this*/
System.out.println( "Computer : Scissors");
}
  
System.out.println( "User : "+userChoice);
  
  
/*check the winner*/
/*if userChoice 1*/
if (userChoice.equals("Rock"))
{
/*than check computerChoice and print according to it*/
if(computerChoice==3)
{
System.out.println( "User win !!!");
}
else if(computerChoice==2)
{
System.out.println("Computer win !!!");
}
else
{
System.out.println("Tie !!!");   
}
}
else if (userChoice.equals("Paper"))
{
/*than check computerChoice and print according to it*/
if(computerChoice==3)
{
/*print this if User win*/
System.out.println( "Computer win !!!");
}
else if(computerChoice==1)
{
/*print this if Computer win*/
System.out.println("User win !!!");
}
else
{
/*print this if same*/
System.out.println("Tie !!!");
}
}
else if (userChoice.equals("Scissor"))
{
/*than check computerChoice and print according to it*/
if(computerChoice==2)
{
/*print this if User win*/
System.out.println( "User win !!!");
}
else if(computerChoice==1)
{
/*print this if Computer win*/
System.out.println("Computer win !!!");
}
else
{
/*print this if same*/
System.out.println("Tie !!!");
}
}
   }
}


Related Solutions

In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper,...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: • Rock beats scissors, because a rock can break a pair of scissors. • Scissors beats paper, because scissors can cut paper. • Paper beats rock, because a piece of paper can cover a rock. Create a game...
Background: In the game “Rock, Paper, and Scissors,” two players simultaneously say (or display a hand...
Background: In the game “Rock, Paper, and Scissors,” two players simultaneously say (or display a hand symbol representing) either “rock,” “paper,” or “scissors.” The winner is the one whose choice wins over the other. The rules are: paper wins over (wraps) rock, rock wins over (breaks) scissors, and scissors wins over (cuts) paper. Assignment: A customer wants you to design and implement a program (RPS.py) for playing the game of “Rock, Paper, Scissors” for a single player against the computer....
Two players play a rock-paper-scissors game. The losing player will give $1 to the winning player....
Two players play a rock-paper-scissors game. The losing player will give $1 to the winning player. If it is a draw, no payment is made. The payoff to a player is the amount of money (s)he gets. Represent the situation in a matrix form. Find all the Nash equilibria.
Q1. Consider the following game. Two players simultaneously and independently choose one of three venues. They...
Q1. Consider the following game. Two players simultaneously and independently choose one of three venues. They would like to choose the same venue (i.e. meet), but their favorite venues are different: Football cafe ballet Football (3,2) (1,0) (1,1) cafe (0,0) (2,2) (0,1) ballet (0,0) (0,0) (2,3) a. What are the pure-strategy Nash equilibria of this game? b. Derive a mixed-strategy Nash equilibrium in which players 1 and 2 mix over Football and Cafe only? Now suppose that player 1 is...
One file java program that will simulate a game of Rock, Paper, Scissors. One of the...
One file java program that will simulate a game of Rock, Paper, Scissors. One of the two players will be the computer. The program will start by asking how many winning rounds are needed to win the game. Each round will consist of you asking the user to pick between rock, paper, and scissors. Internally you will get the computers choice by using a random number generator. Rock beats Scissors, Paper beats Rock, and Scissors beats Paper. You will report...
Solve the scissors, paper, rock game. This game is well known in many parts of the...
Solve the scissors, paper, rock game. This game is well known in many parts of the world. Two players simultaneously present a hand in one of three positions: an open hand (paper), a closed fist (rock), or two open fingers (scissors). The payoff is 1 unit according to the rule “Paper covers rock, rock breaks scissors, and scissors cut paper.” If both players present the same form, the payoff is 0. Set up the payoff matrix for the game and...
Consider now the following two-player simultaneous-move game, called the rock-paper-scissors-lizard game. R stands for rock, P...
Consider now the following two-player simultaneous-move game, called the rock-paper-scissors-lizard game. R stands for rock, P for paper, S for scissors, and L for lizard. R beats S but loses against P and L; P beats R but loses against S and L; S beats P and L but loses against R; L beats R and P but loses against S. The payoffs for winning is 1 and that for losing is -1; when both players choose the same strategy...
Game Description: The popular rock-paper-scissors game is usually played between two people in which each player...
Game Description: The popular rock-paper-scissors game is usually played between two people in which each player simultaneously chooses either a rock or a paper or scissors (usually with an outstretched hand). The rule of the game is simple: rock crushes scissors, scissors cut paper, and paper wraps rock. If both the players choose the same object, then it ends in a tie. Problem Description: You have to play the rock-paper-scissors game against the computer for 100 times. You receive the...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: You can set these constant global variables at the top outside of your main function definition: COMPUTER_WINS = 1 PLAYER_WINS = 2 TIE = 0 INVALID = 3 ROCK = 1 PAPER = 2 SCISSORS = 3 For this program 1 represents rock, 2 represents paper, and 3 represents scissors. In...
Write a Java class that determines the winner of a rock, paper scissors game. Assume the...
Write a Java class that determines the winner of a rock, paper scissors game. Assume the input from the user is always valid (so no need to check), that is it contains either one of `R`, `P`, or `S` as a single character, or has matching parenthesis, like, `(S&P)` or `((R&P)&S)`, and the `&` character. So for example, the user inputs `(P&R)` and the program will output `P` since paper beats rock. Or if the user inputs `((S&R)&(S&S))` the output...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT