wood burning stoves 2.0*
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Rock,Paper Scissors" Watch "Rock,Paper Scissors" New topic
Author

Rock,Paper Scissors

David Record
Greenhorn

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
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

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

Joined: Feb 26, 2001
Posts: 4419
    
    5

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 - [How to Ask Questions] [How to Answer Questions]
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rock,Paper Scissors
 
Similar Threads
Refactoring Exercise
Scissors-rock-paper game looking for better way to write the program
i need help letting a user input anything all upercase, lowercase, or both.
Changing a variable reference from a Superclass object to Subclass
please help! simple java program of rock paper scissors