//RockPaperScissors.java
import java.util.Random;
import java.util.Scanner;
public class RockPaperScissors {
private static boolean playAgain(Scanner scanner) {
System.out.println("Play again? Y(8), N(9)?");
switch (scanner.nextInt()) {
case 8:
System.out.println("Rock, Paper, Scissors!");
return true;
default:
System.out.println("Thanks for playing!");
return false;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
RPSPlayer computer = new RandomComputerPlayer(new Random());
RPSPlayer human = new HumanPlayer(scanner);
// Count the number of wins
int winCount = 0;
System.out.println("Rock Paper Scissors");
do {
for (int i = 1; i <= 3; i++) {
String comp = computer.play();
String you = human.play();
System.out.printf("%s vs. %s\n", comp, you);
if (you.equals(comp)) {
System.out.println(", IT'S A TIE!");
} else if (("Rock".equals(you) && "Scissors".equals(comp))
|| ("Scissors".equals(you) && "Paper".equals(comp))
|| ("Paper".equals(you) && "Rock".equals(comp))) {
winCount++;
}
}
if (winCount >= 2)
System.out.println("! You win!");
else
System.out.println("! You lose!");
} while (playAgain(scanner));
}
}
//RPSPlayer.java
public interface RPSPlayer {
String[] CHOICES = new String[] { "Rock", "Paper", "Scissors" };
/**
* Returns one of "Rock", "Paper", or "Scissors".
*/
String play();
}
//HumanPlayer.java
import java.util.Scanner;
public class HumanPlayer implements RPSPlayer {
private final Scanner scanner;
public HumanPlayer(Scanner scanner) {
this.scanner = scanner;
}
public String play() {
System.out.println("Select 1, 2, or 3 for Rock, Paper, Scissors");
int choice = this.scanner.nextInt();
// Keeping things simple, not doing any validation here
return CHOICES[choice - 1];
}
}
//RandomComputer.java
import java.util.Random;
public class RandomComputerPlayer implements RPSPlayer {
private final Random random;
public RandomComputerPlayer(Random random) {
this.random = random;
}
public String play() {
return CHOICES[this.random.nextInt(CHOICES.length)];
}
}
Output:

Objective: Write a program that simulates a game of rock, paper, scissors between a human and...
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...
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...
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....
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...
(c++ only)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, the user enters his or her choice of “rock”, “paper”, or “scissors” at the keyboard using a menu in a function, userChoice, that returns a character. Next, there should be a function, computerChoice, that generates the computer’s play. A random number in the range of 1 through 3 is generated. If the...
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....
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...
(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...
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....
Write a computer game based on rock-paper- scissors in C++. The 2-player game will be interactive: human vs. computer! Making the game interactive presents a new issue for us -- how do we get the computer's choice? To solve this, we will use a "random number generator", which is the basis for all computer gaming. This enables the properly programmed computer to act like it is actually "thinking" and making its own decisions. This is the largest, most involved program...