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

Airplane Seating Chart System Simulation in Java
Homework Solution
$30.00
Java
Programming
Codes
Computer Science
Algorithms
Airplane Seating Chart
Simulation
Tickets
Seats
Diagrams
Coordinates
Customers
Passengers
Methods
Statements
Variables
Roman Numerals in Java
Homework Solution
$35.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Roman Numerals
Integers
Messages
Input
Output
Arabic Format
Strings
Integers
Java Program: True/False Answers
Homework Solution
$30.00
Java
Programming
Computer Science
Lecturer
Weekly Texts
Students
True/False Answers
Scores
Tests
Questions
Validation
Variables
Loops
Conditions
Java Programming: Arrays Of Marks & Circles
Homework Solution
$50.00
Java
Programming
Codes
Computer Science
Algorithms
Arrays
Marks
Circles
Geometry
Mathematics
Radius
Random Numbers
Boundaries
Statements
Loops
Variables
Points
Coordinates
Perimeters
Area
Generic Method For Java Arrays
Homework Solution
$20.00
Java
Programming
Coding
Computer Science
Arrays
Items
Generic Method
Integers
WordList
Strings
Testing
Primitive Types
Input
Output
Java Problems With Stack
Homework Solution
$40.00
Java
Programming
Coding
Computer Science
Stack
Generic Types
Push
Pop
Peek
Size
Linked List
Functions
Strings
Integers
Summation
Negative Values
Input
Output
Get help from a qualified tutor
Live Chats