This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Rock,Paper Scissors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Rock,Paper Scissors" Watch "Rock,Paper Scissors" New topic

Rock,Paper Scissors

David Record

Joined: Jun 14, 2001
Posts: 7
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

Joined: Mar 01, 2001
Posts: 233
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
since it is the actual string you want to check not the String reference.
Hope this gets you going again
David Record

Joined: Jun 14, 2001
Posts: 7
hey thanks a lot,
that fixed my problem
Junilu Lacar

Joined: Feb 26, 2001
Posts: 4442

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.
[This message has been edited by JUNILU LACAR (edited June 14, 2001).]

Junilu - [How to Ask Questions] [How to Answer Questions]
Junilu Lacar

Joined: Feb 26, 2001
Posts: 4442

David, in case you are interested, I started a thread in the Refactoring forum to show how this program can be improved:
I agree. Here's the link:
subject: Rock,Paper Scissors
Similar Threads
please help! simple java program of rock paper scissors
Refactoring Exercise
Changing a variable reference from a Superclass object to Subclass
i need help letting a user input anything all upercase, lowercase, or both.
Scissors-rock-paper game looking for better way to write the program