Win a copy of Terraform in Action this week in the Cloud forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Rock,Paper Scissors

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having a problem with this code. The counters in the "if" statements are not working. Can anyone help me? I've included both files here.


[This message has been edited by Cindy Glass (edited June 14, 2001).]
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your
else if((p1Choice.equals("paper"))&&(p2Choice.equals("rock")))
you are checking for "paper", "rock", and "scissors"
but, you have defined your choices as
choice = ("Rock");
with the first letter capitalized "Rock", "Paper" and Scissors".
So paper does not equal Paper...; therefore, you never fall into you if statements meaning the counters are never incremented.
Also for your draw check you are using
if(p1Choice == (p2Choice))
but you should be using
if(p1Choice.equals(p2Choice))
since it is the actual string you want to check not the String reference.
Hope this gets you going again
 
David Record
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey thanks a lot,
that fixed my problem
Dave
 
Sheriff
Posts: 16707
278
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David,
There are quite a number of things that you could do to make this a better and cleaner program. And although it may work, it simply is not object-oriented. If you're interested, I could show you how to clean it up but I think it would be better to start a new thread in the Refactoring forum.
Thanks,
Junilu
[This message has been edited by JUNILU LACAR (edited June 14, 2001).]
 
Junilu Lacar
Sheriff
Posts: 16707
278
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David, in case you are interested, I started a thread in the Refactoring forum to show how this program can be improved: http://www.javaranch.com/ubb/Forum9/HTML/000442.html
 
reply
    Bookmark Topic Watch Topic
  • New Topic