Question
Rock, Paper, Scissors! points In this problem, you'll play a simple rock, paper, scissors game. First, you'll ask the user to pick rock, paper, or
Rock, Paper, Scissors! points 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 (input = "")
Note: You'll need to implement a method called String get winner(string user, String computer). Luckily, you just wrote that in an earlier program! Here is a sample run of the program. Enter your choice (rock, paper, or scissors):
rock User: rock Computer: paper Computer paper User: paper Computer scissors Computer wins! Exercise : Rock, Paper, Scissors! 6 points you just wrote that in an earlier program! Here is a sample run of the program Enter your choice (rock, paper, or scissors):rock User: rock Computer: paper Computer wins! Enter your choice (rock, paper, or scissors): paper User: paper Computer: scissors Computer wins! Enter your choice (rock, paper, or scissors):scissors User: scissors Computer:
paper User wins! Enter your choice (rock, paper, or scissors) :rock User: rock Computer: rock Tie Enter your choice (rock, paper, or scissors): Thanks for playing! 4.7.11 Rock, Paper, Scissors! Submit + Conti BPO VO WNH 2 public class Rock Paper Scissors extends Console Program 3- { private static final String USER_PLAYER = "User wins!"; private static final String COMPUTER_PLAYER "Computer wins!"; private static final String TIE = "Tie"; 9- 10 11 12} private String get Winner(String user, String computer) { I
sol43:
Here's an example solution in Java:
```java
import java. Until. Random;
import java .until. Scanner;
public class Rock Paper Scissors {
private static final String USER_PLAYER = "User wins!";
private static final String COMPUTER_PLAYER = "Computer wins!";
private static final String TIE = "Tie";
private static String get Winner(String user, String computer) {
if (user. equals(computer)) {
return TIE;
} else if (user. equals("rock") && computer. equals("scissors") ||
user. equals("paper") && computer. equals("rock") ||
user. equals("scissors") && computer. equals("paper")) {
return USER_PLAYER;
} else {
return COMPUTER_PLAYER;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
while (true) {
System. out. print("Enter your choice (rock, paper, or scissors): ");
String user Choice = scanner. Next Line();
if (user Choice. Is Empty()) {
System. out. Print lnto ("Thanks for playing!");
break;
}
String[] options = {"rock", "paper", "scissors"};
String computer Choice = options[random. Next Into (3)];
System. out. Print ln("User: " + user Choice);
System. out. Print ln("Computer: " + computer Choice);
String result = get Winner(user Choice, computer Choice);
System. out. Print ln(result);
}
scanner. close();
}
}
```
In this program, the `get Winner` method compares the choices of the user and computer to determine the winner. The main program repeatedly prompts the user for their choice, generates a random choice for the computer, and then calls the `get Winner` method to determine the outcome. The game continues until the user hits enter (empty input).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started