1. Member
Join Date
Nov 2011
Location
Statesboro, GA
Posts
3
Rep Power
0

## Rock paper scissors.

Hi everyone,

I'm writing a Rock, Paper, Scissors program in Java. I am in my first Java class and I am still new at this :(
So far I have it so that the user enters a number that corresponds with their choice. I am supposed to error check the user input to make
sure it is either Rock, Paper or Scissors, and if not, they will be prompted to enter it again. I'm supposed to use a do/while loop to allow the
user to continue playing games until ready to quit, and what's scaring me the most, is I have to use a multi-dimensional array to store the user's choices and the computer's choices for each round, and output the game details for each round.

Thanks,
Katie

PS
I attached the structure part of the program that I am using to try and figure out these problems I'm having.

2. ## Re: Rock paper scissors.

If you want help, you'll have to provide an SSCCE that demonstrates where you're stuck. What have you tried? What works, what doesn't work? How doesn't it work?

Break your problem up into tiny pieces, and focus on one small step at a time. What is the very next, smallest thing you know you have to do?

3. ## Re: Rock paper scissors.

But I guess you didn't like that suggestion?

Crossposted: Rock paper scissors project

4. Member
Join Date
Nov 2011
Location
Statesboro, GA
Posts
3
Rep Power
0

## Re: Rock paper scissors.

Thank you for your reply, I am trying to break it down now. I will post back later.

As for your pointing out crossposts, I'm just trying to get as much insight from as many people as I can.

5. ## Re: Rock paper scissors.

As Kevin wrote: solve the problem in tiny pieces; maybe one tiny piece that might help is this: you think of Rock, Paper, Scissors, but your computer might prefer the numbers 0, 1 and 2. 0 wins from 1, 1 wins from 2 and 2 wins from 0. Mathematically speaking x wins from (x+1)%3 where x is 0, 1 or 2 (check it). b.t.w. the % operator is Java's modulo operator. Keeping track of pairs of numbers and comparing them is easier than having to deal with Strings. Of course us humans prefer to think of Rocks, Paper and Scissors, but that's just because humans are strange creatures ;-)

kind regards,

Jos

6. ## Re: Rock paper scissors.

An alternative solution that you'll probably not want to use, but may give you some ideas was one that I posted here: stackoverflow: no-desired-output-probable-cause-is-an-overload. It uses enums and a payout matrix which is a bit of overkill perhaps.

7. Member
Join Date
Nov 2011
Location
Statesboro, GA
Posts
3
Rep Power
0

## Re: Rock paper scissors.

Originally Posted by JosAH
As Kevin wrote: solve the problem in tiny pieces; maybe one tiny piece that might help is this: you think of Rock, Paper, Scissors, but your computer might prefer the numbers 0, 1 and 2. 0 wins from 1, 1 wins from 2 and 2 wins from 0. Mathematically speaking x wins from (x+1)%3 where x is 0, 1 or 2 (check it). b.t.w. the % operator is Java's modulo operator. Keeping track of pairs of numbers and comparing them is easier than having to deal with Strings. Of course us humans prefer to think of Rocks, Paper and Scissors, but that's just because humans are strange creatures ;-)

kind regards,

Jos
I currently have a user input dialog that asks the user to input a number (0,1,2) for either rock, paper or scissors, and the game works fine. Unfortunately, the new project calls for the user to input
the word instead of a number :/. I am trying to figure out how to use a string for both the user's input and the computers random input. So far I get errors of incompatible operand types String and int.
Is there a way that I can convert the user's input of the word Rock, Paper, or Scissors back to a number, so that I can leave the if statement as is? This seems like it would be the easiest thing to do?

I am thinking of using a switch statement for the computer's choice that maybe could solve this. Something like:
case 0:
computerChoice = "Rock";
break;
etc.

Last edited by katie_gsu; 11-29-2011 at 03:05 AM.

8. ## Re: Rock paper scissors.

Using a switch sounds good. Or you could place the Strings into an array and use the choice as the index into the array. Or you could use an enum which has already been suggested.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•