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 chooses rock, paper, or scissors.

Let the user enter a number 1, 2, or 3, each representing one of the three choices.

Then, determine the winner. Save the application as

RockPaperScissors.java

.

(In the chapter “Characters, Strings, and the

StringBuilder

,” you will modify the

game so that the user enters a string for

rock, paper

, and

scissors

, rather than just

entering a number.)

Solutions

Expert Solution

Thanks for the question.


Below is the code you will be needing  Let me know if you have any doubts or if you need anything to change.


The question does refers to an existing class but I see it was not shared here, hence I had to write the whole program from scratch.

Based on my best of my understanding I have written the program, if anything needs to change or modified please do comment and I will make the necessary changes. 


Thank You !!



===========================================================================

import java.util.Scanner;

public class RockPaperScissors {

    public static void main(String[] args) {

        String playerOne, playerTwo;


        Scanner scanner = new Scanner(System.in);
        System.out.print("Player 1: Please type Rock, Paper or Scissors: ");
        playerOne = scanner.nextLine();

        System.out.print("Player 2: Please type Rock, Paper or Scissors: ");
        playerTwo = scanner.nextLine();


        printWinner(playerOne, playerTwo);


    }


    // method that contains logic to determine the winner
    // and print the results
    private static void printWinner(String playerOne, String playerTwo) {


        if (playerOne.equalsIgnoreCase("rock") &&
                playerTwo.equalsIgnoreCase("scissors")) {
            System.out.println("Player 1 is the winner!");
        } else if (playerOne.equalsIgnoreCase("scissors") &&
                playerTwo.equalsIgnoreCase("paper")) {
            System.out.println("Player 1 is the winner!");
        } else if (playerOne.equalsIgnoreCase("paper") &&
                playerTwo.equalsIgnoreCase("rock")) {
            System.out.println("Player 1 is the winner!");
        } else if (playerOne.toUpperCase().equals(playerTwo.toUpperCase())) {
            System.out.println("Match Draw!");
        }
        else if (playerTwo.equalsIgnoreCase("rock") &&
                playerOne.equalsIgnoreCase("scissors")) {
            System.out.println("Player 2 is the winner!");
        } else if (playerTwo.equalsIgnoreCase("scissors") &&
                playerOne.equalsIgnoreCase("paper")) {
            System.out.println("Player 2 is the winner!");
        } else if (playerTwo.equalsIgnoreCase("paper") &&
                playerOne.equalsIgnoreCase("rock")) {
            System.out.println("Player 2 is the winner!");
        } else {
            System.out.println("Invalid inputs!");
        }
    }
}

===========================================================================


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...
write a python script for rock scissors paper game
write a python script for rock scissors paper game
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT