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

Huffman Coding in Java
Homework Solution
$25.00
Computer Science
Java Programming
Huffman Coding
Frequency
Tables
Symbols
Punctuation Marks
Input
Output
Digits
Java Programming Questions
Homework Solution
$25.00
Computer Science
Java Expression
Programming
Language
JSP EL
Dot Operator
JavaBeans
Data
Syntax
Operator
Java Programming Problems
Homework Solution
$45.00
Computer Science
Java Programming
Backtracking Algorithm
Queens
Logic
Boards
Rows
Columns
Driver Class
Standard Output
Financial Application in Java
Homework Solution
$15.00
Computer Science
Java Programming
Financial Applications
Payroll
Hourly Rates
Withholding Rate
Tax
Deductions
Net Pay
Packing Books Simulation in Java
Homework Solution
$15.00
Computer Science
Java Programming
Packing Books
Simulation
Boxes
Space
Shipping
Codes
Objects
Users
Methods
Get help from a qualified tutor
Live Chats