Question: Java, need a program that has test and data Remember the childhood game Rock, Paper, Scissors? It is a two-player game in which each person

Java, need a program that has test and data

Remember the childhood game Rock, Paper, Scissors? It is a two-player game in which each person simultaneously chooses either rock, paper, or scissors. The rules are: Rock beats scissors but loses to paper Paper beats rock but loses to scissors Scissors beats paper but loses to rock Write the code to create the game. Name your class "RockPaperScissorsYourLastName.java". Prompt player 1 and player 2 to each enter a string: rock, paper, or scissors. Pass those values to a method you create to determine the winner and return a winner. Plan your code so that if they input with capitals, the game will still play. Use a nested if statement to determine the winner (not AND or OR statements in the condition of your if statements). Set the winner in your if statement. DO NOT PRINT THE WINNER FROM THIS IF STATEMENT. You should use this if statement just SET the winner. Keep your view separate from the logic of this if statement. Print the winner from the main method. Use efficient if statements. Remember: you don't have to check every possible situation. Write a test to test your method.

my program so far, barring changes: import java.util.Scanner; public class RockPaperScissorslastname { public static void main(String[] args){ Scanner pick = new Scanner(System.in); int c1=-1; //player 1's choice int c2=-1; // player 2's choice 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(); if(s1.equals("rock")){ c1 = 0; } else if(s1.equals("scissors")) { c1 = 1; } else if(s1.equals("paper")) { c1 = 2; } System.out.println("Player 2: Choose rock, scissors, or paper:"); s2 = pick.next(); s2=s2.toLowerCase(); if(s2.equals("rock")){ c2 = 0; }else if(s2.equals("scissors")){ c2 = 1; }else if(s2.equals("paper")){ c2 = 2; } if(c1 == c2){ System.out.println("It's a draw! You both chose the same object" + " which is: " + s1 +"."); }else if((c1 == 2 && c2 == 1 && c1 < 3) || (c1 == 0 && c2 == 2 && c1 <3) || (c1 == 1 && c2 == 0 && c1 <3) ){ System.out.println("Player 2 wins."); }else if((c1 == 1 && c2 == 2 && c1 < 3) || (c1 == 0 && c2 == 1 && c1 <3) || (c1 == 2 && c2 == 0 && c1 <3)){ System.out.println("Player 1 wins."); }else{ System.out.println("Wrong choice!"); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!