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 ends.
play() has no parameters, and no return value. (In this exercise, the class RPS does contain code that will input and output to the user.) Use GUI for all input and output. Note that since play() is a static method, it can be called directly on the RPS class -- main() should not instantiate an RPS object. play() will allow one full game of RPS to run. To win an RPS game, the player or the computer must win 2 out of 3 rounds.
The following should all be done inside the RPS class:
The java code is as follows :
import java.util.*;
enum State
{
WIN, LOSE, TIE;
}
class RPS
{
//Constants to represent rock, paper and
scisoors
protected static final int ROCK = 1;
protected static final int PAPER = 2;
protected static final int SCISSORS = 3;
protected static State playerState;
public static void play()
{
Random ran = new Random();
Scanner in = new
Scanner(System.in);
int playerChoice;
int CPUChoice;
int playerWonCount = 0;
int CPUWonCount = 0;
System.out.println("Welcome to Rock, Paper, Scissors!!");
for (int i = 0; i < 3;
i++)
{
System.out.println("\nRound : " + (i + 1) + " - ");
System.out.print("Enter " + RPS.ROCK + " for rock, " + RPS.PAPER +
" for paper, and " + RPS.SCISSORS + " for scisoors :- ");
playerChoice =
in.nextInt();
CPUChoice = ran.nextInt(3) + 1;
System.out.print("\nYou choose : ");
if (playerChoice
== RPS.ROCK)
System.out.println("Rock");
else if
(playerChoice == RPS.PAPER)
System.out.println("Paper");
else
System.out.println("Scissors");
System.out.print("CPU choose : ");
if (CPUChoice ==
RPS.ROCK)
System.out.println("Rock");
else if
(CPUChoice == RPS.PAPER)
System.out.println("Paper");
else
System.out.println("Scissors");
if
(playerChoice == CPUChoice)
System.out.println("\nIts a tie!!");
else if (
(playerChoice == RPS.PAPER && CPUChoice == RPS.ROCK) ||
(playerChoice == RPS.ROCK && CPUChoice ==
RPS.SCISSORS)
|| (playerChoice == RPS.SCISSORS &&
CPUChoice == RPS.PAPER) )
{
System.out.println("\nYou won the
round!!");
playerWonCount++;
}
else
{
System.out.println("\nCPU won the
round!!");
CPUWonCount++;
}
}
if (CPUWonCount ==
playerWonCount)
RPS.playerState
= State.TIE;
else if (CPUWonCount >
playerWonCount)
RPS.playerState
= State.LOSE;
else
RPS.playerState
= State.WIN;
switch(RPS.playerState)
{
case TIE :
System.out.println("\n\nThe game was a
tie!!\n");
break;
case WIN :
System.out.println("\n\nYou
won the game!!\n");
break;
case LOSE
:
System.out.println("\n\nCPU
won the game\n");
break;
}
}
public static void main(String args[])
{
char ch = ' ';
Scanner in = new
Scanner(System.in);
while(true)
{
System.out.print("Do you want to play(y/n) : ");
ch =
in.next().charAt(0);
if (ch != 'n'
&& ch != 'N')
RPS.play();
else
break;
}
System.out.println("\n\nGame
Ended!!");
}
}
OUTPUT :

Java CSC252 Programming II Static Methods, Enums, Constants, Random Rock Paper Scissors Write a program that...
C++ Write a program that plays the rock, paper, scissors game. Rock beats scissors; scissors beats paper; paper beats rock. You must use these specific functions in your program. These are the prototypes: char generateP2toss(); int checkThrow(char, char); void printStatistics(int, int, int, int); void finalStatistics(int, int, int, int); void welcome(); Notes on these functions: generateP2toss() will generate the computer's toss (the computer is player2). It returns either an "r", "p", or "s/" checkThrow(char char) will check the throw by passing...
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...
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...
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...
Write a program in python that lets the user play the game 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. 2 corresponds to paper, and 3 corresponds to scissors. To set up the random number library, write the following at the top of your code: import random random.seed(300) Use...
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....
For this week’s assignment, we will be recreating the Rock, Paper, Scissors program using Object-Oriented Programming. You will be working with me on a team to build the program. I have already written my part of the program, and the Game.java file is attached. Your task will be to write a RockPaperScissors class that contains the following methods: getUserChoice: Has the user choose Rock, Paper, or Scissors. After validating the input, the method returns a String containing the user choice....
(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...
Objective: Write a program that simulates a game of rock, paper, scissors between a human and the computer in best 2 out of 3 rounds. Requirements: . The player can enter either "rock", "paper", or "scissors'". o If the player enters anything other than that the computer automatically gets a point . The computer randomly selects one of the gestures o Use the Random type to make this easier o Also make sure you import java.util.Random o You can use...
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...