Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language = Java Modify your Rock Paper Scissor (Lizard/Spock) game from Week 5 to generate a random number for Player 2 and assign that as

Language = Java

Modify your Rock Paper Scissor (Lizard/Spock) game from Week 5 to generate a random number for Player 2 and assign that as Player 2's choice. The rest of your program should stay the same. You can use your program with the nested if statements or the switch statement. The implementation should use the Random class to get your random number.

My Rock Paper Scissor (Lizard/Spock) game from Week 5 Below

import java.util.*; public class RPSLS { public static String findWinner(String s1, String s2) { String win = ""; switch (s1) { case "rock": switch (s2) { case "rock": win = "Draw"; break; case "scissors": win = "1"; break; case "paper": win = "2"; break; case "spock": win = "2"; break; case "lizard": win = "1"; break; } break; case "scissors": switch (s2) { case "rock": win = "2"; break; case "scissors": win = "Draw"; break; case "paper": win = "1"; break; case "spock": win = "2"; break; case "lizard": win = "1"; break; } break; case "paper": switch (s2) { case "rock": win = "1"; break; case "scissors": win = "2"; break; case "paper": win = "Draw"; break; case "spock": win = "1"; break; case "lizard": win = "2"; break; } break; case "spock": switch (s2) { case "rock": win = "1"; break; case "scissors": win = "1"; break; case "paper": win = "2"; break; case "spock": win = "Draw"; break; case "lizard": win = "2"; break; } break; case "lizard": switch (s2) { case "rock": win = "2"; break; case "scissors": win = "2"; break; case "paper": win = "1"; break; case "spock": win = "1"; break; case "lizard": win = "Draw"; break; } break;

} return ("Player " + win + " wins!"); }

public static void main(String[] args) { String s1, s2; String win = ""; Scanner scan = new Scanner(System.in); System.out.print("Enter Player 1 Selection (rock, paper, scissors, lizard or spock):"); s1 = scan.next(); System.out.print("Enter Player 2 Selection (rock, paper, scissors, lizard or spock):"); s2 = scan.next(); System.out.println(findWinner(s1.toLowerCase(), s2.toLowerCase())); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+5. Is the public perception about your organization correct?

Answered: 1 week ago