Write a program that lets the user play the game of Rock, Paper, Scissors against the computer.
When the program begins, a random number in the range of 1 through 3 is generated. Don’t display the computer’s choice yet.
The user enters his or her choice of “rock”, “paper”, or “scissors” at the keyboard. Gather this input using JOptionPane.showInputDialog().
Display the computer’s choice.
A winner is selected according to the following rules:
• If one player chooses rock and the other player chooses scissors, then rock wins.
Display something to the effect of: “Rock smashes the scissors.”
• If one player chooses scissors and the other player chooses paper, then scissors wins.
Display something like: “Scissors cuts paper.”
• If one player chooses paper and the other player chooses rock, then paper wins.
Display something like: “Paper wraps rock.”
• If both players make the same choice, run the game again to determine the winner.
Once a winner is determined, display the winner on the screen.
With this, my only question is with "Gather this input using JOptionPane.showInputDialog()." I accidentally skipped over it when I started and now have to backtrack. I've looked it up and have even reread my book but can't figure out how to implement this and have it be given as the user input. I'm thinking I may have to rewrite my code based around it.
Sorry for the cluttered code, I have to fit as much in as few pictures possible to submit and caught this right before.
Formatting is one of the things they ought to have told you on day 1 of your course. It is important. You have a great big block of illegible code there. We have some suggestions here. You won't get everybody agreeing with those suggestions, however.
I am surprised you are supposed to use option panes; they do work but that is a very old‑fashioned programming style. There is a section in the Java™ Tutorials about that. When you call the showXXX() methods, you will probably have to make the first argument null because there isn't a Component to appear in front of. In theory the dialogue will appear in the centre of the screen, but I have known it to appear behind something, so you might need to minimise everything to see the dialogue.
No, tomorrow we rule the world! With this tiny ad: