Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Junit Test for this to check for typos and or invalid characters... import java.util.Scanner; public class RockPaperScissorsYourLastName { public static int findWinner(String s1,String

Create a Junit Test for this to check for typos and or invalid characters... import java.util.Scanner; public class RockPaperScissorsYourLastName { 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

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions

Question

4 How the market system adjusts to change and promotes progress.

Answered: 1 week ago