Write a Rock, Paper, Scissors program in the language of your choice. User plays computer. User should have a 40% probability of winning each round.
Optional: Write a CREATE TABLE MySQL statement that could be used to save the results of each round.
Show your thought process, knowledge of a programming language, and adherence to standards.
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
import java.awt.event.ActionListener;
import javax.swing.*;
public class RockPaperScissors {
public static ImageIcon[] icons = {new ImageIcon("Rock.png"), //FIle names
new ImageIcon("Scissors.png"),
new ImageIcon("Paper.png")};
public static String[] names = {"Rock", "Scissors", "Paper"};
//Names of plays
private static JButton rock, paper, scissors; //Stuff for GUI
private static JLabel player, computer, playerImage, computerImage, winnerLabel;
private static JPanel buttons, images;
private static JFrame frame;
private static MySQL sql;
public RockPaperScissors()
{
sql = new MySQL(); //Start up the sql connection
frame = new JFrame("Rock Paper Scissors"); //Create frame
buttons = new JPanel(new GridLayout(1, 3)); //Initialize panels
images = new JPanel(new GridBagLayout());
winnerLabel = new JLabel("Winner: ");
GridBagConstraints c = new GridBagConstraints();
rock = new JButton("Rock");
rock.addActionListener(new ActionListener() { //Add listener for rock button
public void actionPerformed(ActionEvent e)
{
int choice = 0; //CHoice is 0 for rock
String winner;
int computerChoice = rockPaperScissors(choice); //Play game
playerImage.setIcon(icons[choice]);...
This is only a preview of the solution. Please use the purchase button to see the entire solution