are you familiar with joptionpane?
import java.util.Random; public class Choice { private static final String[] PHRASE = { "rock mirrors rock", "rock breaks scissors", "rock crushes lizard", "Spock mirrors Spock", "Spock vaporizes rock", "Spock smashes (or melts) scissors", "paper mirrors paper", "paper disproves Spock", "paper covers rock", "lizard mirrors lizard", "lizard eats paper", "lizard poisons Spock", "scissors mirrors scissors", "scissors decapitate lizard", "scissors cut paper" }; private static final int ROCK = 0, SPOCK = 1, PAPER = 2, LIZARD = 3, SCISSORS = 4; private static final int COMPUTER = -1, TIE = 0, PLAYER = 1; private static Random rand = new Random(System.currentTimeMillis()); private int playerChoice, computerChoice; private int winner; public Choice(int playerOption) { playerChoice = playerOption; computerChoice = rand.nextInt(5); if (playerChoice == computerChoice) { winner = TIE; return; } if ((playerChoice - computerChoice + 5) % 5 < 3) winner = PLAYER; else winner = COMPUTER; } public int getWinner() { return winner; } public int getPlayerChoice() { return playerChoice; } public int getComputerChoice() { return computerChoice; } public String getPhrase() { int winOpt = 0, loseOpt = 0; if (winner == TIE) winOpt = loseOpt = playerChoice; else if (winner == PLAYER) { winOpt = playerChoice; loseOpt = computerChoice; } else { winOpt = computerChoice; loseOpt = playerChoice; } return PHRASE[winOpt * 3 + (winOpt - loseOpt + 5) % 5]; } }
// int playerOption = [some value that the player chooses] Choice choice = new Choice(playerOption); int computerOption = choice.getComputerChoice(); int winner = choice.getWinner(); String message = choice.getPhrase();
if (winner == Choice.COMPUTER) // or if (computerChoice == Choice.ROCK) // or you could use a switch switch(winner) { case Choice.COMPUTER: // some code break; case Choice.TIE: // some code break; case Choice PLAYER: // some code break; }