• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

Rock Paper Scissors

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Master Rancher
Posts: 4188
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried asking Google this:  input with JOptionPane.showInputDialog()?
There are lots of examples returned.  Try some.  Come back if you have problems or questions.
 
Marshal
Posts: 72059
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

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:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic