Question
(I need the test file AND the Modified Code: This needs to be done ASAP, PLZ HELP!) Modify your Rock Paper Scissor Lizard Spock game
(I need the test file AND the Modified Code: This needs to be done ASAP, PLZ HELP!)
Modify your Rock Paper Scissor Lizard Spock game from Week 6 to generate a random number for Player 2, use the random number to assign it a string selection (rock paper scissor lizard spock) and assign that as Player 2's choice. Complete the work of assigning Player 2's random choice in a method. It should take no parameters but return a string that represents Player 2's random choice. The implementation should use the Random class to get your random number.
Now you are only getting a choice from player one and playing until they enter done using the sentinel value loop. The rest of your program should stay the same. You can use your program with the nested if statements or the switch statement.
Verify that your file still works with your testing file. If Lizard and Spock are not implemented, verify that those tests are added. Make sure all your tests are exhaustive (uppercase, funky case, same plays, all options, bad input). Note: you do not need to test your random player 2 option method. After all, how could you? (The answer is not easily; therefore, you do not need to test it - just your determine who the winner is method.)
The assignment is worth 15 points for the two files. Upload your class and the testing file to the assignment. Both files must be submitted in order to be graded.
Here is my code from Week 6: (I need the test file AND the Modified Code: This needs to be done ASAP, PLZ HELP!)
import java.util.Scanner; public class RockPaperScissorsSivakumar { public static int findWinner(String s1,String s2) { int winner = 0; if(s1.equals("rock")) { // if player 1 chooses rock if(s2.equals("rock")) winner = 0; else if(s2.equals("scissors")) winner = 1; else winner = 2; } else if(s1.equals("scissors")) { // if player 1 chooses scissors if(s2.equals("scissors")) winner = 0; else if(s2.equals("paper")) winner = 1; else winner = 2; } else { // if player 1 chooses paper if(s2.equals("paper")) winner = 0; else if(s2.equals("rock")) winner = 1; else winner = 2; } return winner; } public static void main(String[] args){ Scanner pick = new Scanner(System.in); String s1 = ""; //s1 is player 1's choice string String s2 = ""; //s2 is player 2's choice string System.out.println("Player 1: Choose rock, scissors, or paper:"); s1 = pick.next(); s1 = s1.toLowerCase();
System.out.println("Player 2: Choose rock, scissors, or paper:"); s2 = pick.next(); s2 = s2.toLowerCase();
int winner = findWinner(s1,s2); if(winner == 0) { System.out.println("It's a draw! You both chose the same object" + " which is: " + s1 +"."); } else { System.out.println("Player " + winner + " Wins.");
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