Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rock,Paper Scissors

 
David Record
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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).]
 
Richard Boren
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
hey thanks a lot,
that fixed my problem
Dave
 
Junilu Lacar
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic