/** * Write a description of class choice here. * * @author (your name) * @version (a version number or a date) */ import java.util.Random; import javax.swing.*; import java.awt.event.*; import java.awt.*; public class game implements ActionListener { private int value; private char letter; private JButton rockButton; private JButton scissorButton; private JButton paperButton; public game() { JFrame frame = new JFrame("Rock, Paper, Scissors"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); rockButton = new JButton("Rock"); rockButton.addActionListener(this); scissorButton = new JButton("Scissors"); scissorButton.addActionListener(this); paperButton = new JButton("Paper"); paperButton.addActionListener(this); } private void next(); { Random rand = new Random(); value = rand.nextInt(3) + 1; if(value == 1) { letter = 'R'; } else if (value == 2) { letter = 'S'; } else if (value == 3) { letter = 'P'; } System.out.println("Computer Choice " + letter); } public void actionPreformed(ActionEvent e) { char choice; string str; if(e.getSource() == rockButton) { choice = 'R'; } else if(e.getSource() == scissorButton) { choice = 'S'; } else if(e.getSource() == paperButton) { choice = 'P'; } next(); if((choice == 'R') && (letter == 'R')) { str = "It's a tie!"; } else if((choice == 'R') && (letter == 'S')) { str = "Rock smashes scissors! You win!"; } else if ((choice == 'R') && (letter == 'P')) { str = "Paper covers rock! You lose."; } else if ((choice == 'P') && (letter == 'P')) { str = "It's a tie!"; } else if ((choice == 'P') && (letter == 'R')) { str = "Paper covers rock! You win!"; } else if ((choice == 'P') && (letter == 'S')) { str = "Scissors cut paper! You lose."; } else if ((choice == 'S') && (letter == 'S')) { str = "It's a tie!"; } else if ((choice == 'S') && (letter == 'P')) { str = "Scissors cut paper! You win!"; } else if ((choice == 'S') && (letter == 'R')) { str = "Rock smashes scissors! You lose."; } } }