Question: Create a new Java file called RPSLSYourLastName . Copy your Rock Paper Scissor Lizard Spock game from last unit into it. Modify the method
Create a new Java file called "RPSLSYourLastName". Copy your Rock Paper Scissor Lizard Spock game from last unit into it. Modify the method to use a switch statement instead of nested if statements. If you haven't, implement Lizard & Spock. Everything else should still work for your game. Again, prompt the both player 1 and player 2 for a String (as their selection). Pass that value into your method. Set a default value for the winner (either player 1 or player 2) and switch the value if the other person wins or there is a tie. This image might help you figure out who win.
Report back whether player 1, player 2 or it's a tie. Again, do not print from your decision structure.
Add testing to this program. If you ONLY change the .java file name and the method implementation, you should be able to just modify your testing file from the last unit quickly and everything will still work [you may have to add in testing for Lizard & Spock if you didn't already have it].
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//This is my Rock Paper Scissor Lizard Spock game from last unit
import java.util.*;
public class RockPaperScissorsYourLastName { public static String findWinner(String s1, String s2) { String win=""; if(s1 == s2) win="Draw"; if(s1.equals("rock")) { if(s2.equals("scissors")) win="1"; if(s2.equals("paper")) win="2"; } if(s1.equals("scissors")) { if(s2.equals("paper")) win="1"; if(s2.equals("rock")) win="2"; } if(s1.equals("paper")) { if(s2.equals("rock")) win="1"; if(s2.equals("scissors")) win="2"; } 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, or scissors):"); s1=scan.next(); System.out.print("Enter Player 2 Selection (rock, paper, or scissors):"); s2=scan.next(); System.out.println(findWinner(s1.toLowerCase(), s2.toLowerCase())); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
