For this lab you will create a class RockPaperScissors that will enable you to p
ID: 3697421 • Letter: F
Question
For this lab you will create a class RockPaperScissors that will enable you to play Rock-Paper-Scissors-Lizard-Spock against a computer opponent. Your implementation should contain the following:
public class RockPaperScissors {
public enum Agent {HUMAN , COMPUTER}
final static Outcome RESULTS [][] = {...}
public static int getInput(Agent agent) {...}
public static String displayResult(int a, int b){...} public static void main(String[] args) {
System.out.println("Rock-Paper-Scissors-Lizard-Spock");
int playersMove = getInput(Agent.HUMAN); int computersMove = getInput(Agent.COMPUTER);
displayResult(playersMove , computersMove); }
}
Rock
Paper
Scissors
Lizard
Spock
Rock
Draw
Lose
Win
Win
Lose
Paper
Win
Draw
Lose
Lose
Win
Scissors
Lose
Win
Draw
Win
Lose
Lizard
Lose
Win
Lose
Draw
Win
Spock
Win
Lose
Win
Lose
Draw
Rock
Paper
Scissors
Lizard
Spock
Rock
Draw
Lose
Win
Win
Lose
Paper
Win
Draw
Lose
Lose
Win
Scissors
Lose
Win
Draw
Win
Lose
Lizard
Lose
Win
Lose
Draw
Win
Spock
Win
Lose
Win
Lose
Draw
Explanation / Answer
Here is the code for you:
import java.io.*;
import java.util.Scanner;
public enum Choice {ROCK, PAPER, SCISSOR};
public class ScissorRockPaper
{
Choice ch;
public static void main(String[] args)
{
Choice ch;
Scanner in = new Scanner(System.in);
choice computerNumber = (int)(Math.random() * 3);
System.out.print("Scissor (0), Rock (1), Paper (2): ");
choice userInput = in.nextInt();
switch(computerNumber)
{
case Scissor:
System.out.print("The computer is Scissor. ");
if(userInput == Scissor)
System.out.println("You are Scissor too. It is a draw.");
else if(userInput == Rock)
System.out.println("You are a Rock. You won.");
else
System.out.println("You are a Paper. You lost");
break;
case Rock:
System.out.println("The computer is Rock. ");
if(userInput == Scissor)
System.out.println("You are Scissor. You lost.");
else if(userInput == Rock)
System.out.println("You are a Rock too. Its a draw.");
else
System.out.println("You are a Paper. You won.");
break;
case Paper:
System.out.println("The computer is Paper. ");
if(userInput == Scissor)
System.out.println("You are Scissor. You won.");
else if(userInput == 1)
System.out.println("You are a Rock. You lost.");
else
System.out.println("You are a Paper too. Its a draw.");
break;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.