Question

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.

Solution Preview

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

Related Homework Solutions

ArrayList Fraction Objects in Java
Homework Solution
$15.00
Java
Programming
Computer Science
Coding
Arrays
Fractions
Numerator
Denominator
Decimal Values
Sorted List
Algorithms
Loops
Variables
Statements
Conditions
Java Project For Consulting Company
Homework Solution
$50.00
Java
Programming
Computer Science
Consulting Company
Inventory
Interfaces
Products
Lookup
Classes
Libraries
Queries
Finance
Employees
Management
OOP
Function
Methods
Loops
Conditions
Java Program With Lists & Integers
Homework Solution
$40.00
Java
Programming
Codes
Algorithms
Linked Lists
File Management
Data Structures
Libraries
Scanner
Zero Sum Subset
Input
Output
Statements
Variables
Positive Integers
Negative Integers
Binary Mask
Pseudo-Codes
Java Program With Strings & Integers
Homework Solution
$20.00
Java
Programming
Coding
Strings
Integers
Computer Science
Symbols
Special Characters
Reading
Writing
Rows
Columns
Statements
Conditions
Loops
Java Programming: Printing The Pattern
Homework Solution
$10.00
Java
Programming
Computer Science
Loops
Printing
Patterns
Rows
Loops
Statements
Variables
Integers
Strings
Input
Output
Get help from a qualified tutor
Live Chats