Question

JAVA Beginnings of a paper-rock-scissors game. Paper-rock-scissors is a game often used to make decisions. There...

JAVA

Beginnings of a paper-rock-scissors game.

Paper-rock-scissors is a game often used to make decisions. There are two players. Each player secretly chooses either, paper, rock or scissors. At the count of three, each player reveals what they have chosen.

The winner of the game is determined this way:

paper beats rock (because paper covers rock)

rock beats scissors (because rock crushes scissors)

scissors beat paper (because scissors cut paper)

If the two players choose the same item, it is a tie.

Write a program to play five hands of this game. The computer will play against the human user.

Ask the user to enter his/her choice and the computer will randomly pick a choice. Then the program will determine who wins or if it is a tie and print a message to the screen. After a hand is played. Print who wins the hand. After five hands, print how many each player

(computer and human) won.

Here is sample output:

Enter your choice (P, R, or S) (user enters S)

The computer chose rock, you chose scissors so the computer won!

Use rhe Random methods we used in lecture:

Import java.util.* Random rng = new Random( ); //to get an int in range of 0 through 4: num = rng.nextInt(5);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

JAVA PROGRAM:

import java.util.*;
class Game
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
int i,scoreU=0,scoreS=0;
for(i=0;i<5;i++)
{
System.out.print("User:");
String a=sc.nextLine();
if(a.equals("P")||a.equals("S")||a.equals("R"))
{
Random r=new Random();
int n=r.nextInt(5);
n%=3;
if(n==0)
{
System.out.println("System:P");
}
else if(n==1)
{
System.out.println("System:S");
}
else if(n==2)
{
System.out.println("System:R");
}
if((a.equals("P")&&n==2)||(a.equals("S")&&n==0)||(a.equals("R")&&n==1))
{
scoreU++;
}
else if((a.equals("P")&&n==1)||(a.equals("S")&&n==2)||(a.equals("R")&&n==0))
{
scoreS++;
}
}
else
{
System.out.println("Wrong Choice");
}
}
System.out.println("User Score:"+scoreU);
System.out.println("System Score:"+scoreS);
if(scoreU>scoreS)
{
System.out.println("Winner is User");
}
else if(scoreU<scoreS)
{
System.out.println("Winner is System");
}
else
{
System.out.println("Match Tie");
}
};
};
SAMPLE INPUT OUTPUT:

Hand 1
User:R
System:R
Hand 2
User:S
System:P
Hand 3
User:P
System:S
Hand 4
User:S
System:P
Hand 5
User:R
System:S
User Score:3
System Score:1
Winner is User

Add a comment
Know the answer?
Add Answer to:
JAVA Beginnings of a paper-rock-scissors game. Paper-rock-scissors is a game often used to make decisions. There...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of...

    java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of the common game Rock Paper Scissors that is often used to pass time (or sometimes to make decisions.) The rules of the game are outlined below: • • Scissors cuts Paper Paper covers Rock Rock crushes Lizard Lizard poisons Spock Spock smashes Scissors Scissors decapitates Lizard Lizard eats Paper Paper disproves Spock Spock vaporizes Rock Rock crushes Scissors Write a program that simulates the...

  • Java CSC252   Programming II    Static Methods, Enums, Constants, Random Rock Paper Scissors Write a program that...

    Java CSC252   Programming II    Static Methods, Enums, Constants, Random Rock Paper Scissors Write a program that allows the user to play "Rock, Paper, Scissors". Write the RPS class. All code should be in one file. main() will be part of the RPS class, fairly small, and contain only a loop that asks the user if they want to play "Rock, Paper, Scissors". If they say yes, it calls the static method play() of the RPS class. If not, the program...

  • This program should be in c++. Rock Paper Scissors: This game is played by children and...

    This program should be in c++. Rock Paper Scissors: This game is played by children and adults and is popular all over the world. Apart from being a game played to pass time, the game is usually played in situations where something has to be chosen. It is similar in that way to other games like flipping the coin, throwing dice or drawing straws. There is no room for cheating or for knowing what the other person is going to...

  • IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors...

    IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet....

  • C++ You are asked to implement scissors-rock-paper game where the players are a computer and a...

    C++ You are asked to implement scissors-rock-paper game where the players are a computer and a user. The player that wins 3 hands successively is the winner of the game. Your program should prompt the user with a message at the beginning of each hand to enter one of scissors, rock or paper. If the user’s entry is not valid, i.e. entry is neither scissors, rock, nor paper, your program throws a message to the user to enter a valid...

  • (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against...

    (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet. The...

  • It's writing a simple rock paper scissors game strictly following the instructions. INSTRUCTIONS: If the user...

    It's writing a simple rock paper scissors game strictly following the instructions. INSTRUCTIONS: If the user selects 'p': 1. First the program should call a function named getComputerChoice to get the computer's choice in the game. The getComputerChoice function should generate a random number between 1 and 3. If the random number is 1 the computer has chosen Rock, if the random number is 2 the user has chosen Paper, and if the random number is 3 the computer has...

  • You are asked to implement scissors-rock-paper game where the players are a computer and a user....

    You are asked to implement scissors-rock-paper game where the players are a computer and a user. The player that wins 3 hands successively is the winner of the game. Your program should prompt the user with a message at the beginning of each hand to enter one of scissors, rock or paper. If the user's entry is not valid, i.e. entry is neither scissors, rock, nor paper, your program throws a message to the user to enter a valid entry...

  • Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember...

    Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember the rules: 1. Rock beats scissors 2. Scissors beats paper 3. Paper beats rock The program should ask the users for their names, then ask them for their picks (rock, paper or scissors). After that, the program should print the winner's name. Note, the players may pick the same thing, in this case the program should say it's tie. when the user input an...

  • In this problem, you’ll play a simple rock, paper, scissors game. First, you’ll ask the user...

    In this problem, you’ll play a simple rock, paper, scissors game. First, you’ll ask the user to pick rock, paper, or scissors. Then, you’ll have the computer randomly choose one of the options. After that, print out the winner! You should keep playing the game until the user hits enter. Note: You’ll need to implement a method called String getWinner(String user, String computer). Luckily, you just wrote that in an earlier program! Here is a sample run of the program....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT