only scanners, strings, for loops, while loops, and if/else statements are allowed.

1. main method. In the main program declare a Scanner variable that is hooked up to System.in. You need to include the line of code

import java.util.*;

at the top of your program. Pass the Scanner object you create as a parameter to any methods that need it. The main method should not have a lot of statements, instead it will be calling other methods.

2. ask the user for their name. This is a good candidate for a separate method that returns a String.

3. ask the user how many rounds of Rock, Paper, Scissors they want to play. This is another good candidate for a separate method that returns an int. You do not have to do any error checking on the user input. If they enter something that is not an int it is appropriate for the program to end due to a runtime error.

Recall that if you use the nextInt() method from the Scanner class you will have to call the nextLine() method after that to advance the Scanner past the end of line character. The nextInt() method does not advance past the end of line character.

4. playing the rounds of the game Given our current programming tools this will be the largest and most complex method. It is in turn broken down into several parts. You will need a number of local variables in this method and they should be declared at the top of the method. Obviously you will need a loop to play the appropriate number of rounds.

5. ask the user what their choice is. The user will enter an integer as their choice. You do not need to error check their input. Recall that if you use the nextInt() method from the Scanner class you will have to call the nextLine() method after that to advance the Scanner past the end of line character. The nextInt() method does not advance past the end of line character.

6. have the computer make a random choice. To do this you need the computer to pick a random number between 1 and 3. Create a Random object and then call nextInt() on that Random object repeatedly to produce the random numbers.

7. print out each player's choice. You will find it useful to have a method that is passed an int parameters and returns the correct String for that int. In this program 1 represents "Rock", 2 represents "Paper", and 3 represents "Scissors".

8. print the results of that round. The nine possible outcomes are
Computer Choice Human Choice Result
Rock Rock Draw
Rock Paper Human Wins
Rock Scissors Computer Wins
Paper Rock Computer Wins
Paper Paper Draw
Paper Scissors Human Wins
Scissors Rock Human Wins
Scissors Paper Computer Wins
Scissors Scissors Draw

You can eliminate some redundancy with these nine outcomes, but not much.

9. after playing the specified number of rounds display how time the user won, how many times the computer won, and how many draws occurred. The method that runs the rounds should call a method to display this information.

10. declare who the better player was based on the number of wins. This can be part of the results method but will again require some conditional execution with if statements.

11. Use class constants for the integers representing rock, paper, and scissors. Recall class constants are declared at the top of the class outside any methods:

public static final int ROCK = 1;

Welcome to Rock Paper Scissors. I, the computer, will be your opponent.
Please type in your name and press return: Nathan

Welcome Nathan.
All right Nathan. How many games would you like to play?
Enter the number of rounds you want to play and press return: 9


Round 1.
Nathan, please enter your choice for this round.
1 for rock, 2 for paper, and 3 for scissors: 1
Computer picked rock, Nathan picked rock.

This round is a draw.


Round 2.
Nathan, please enter your choice for this round.
1 for rock, 2 for paper, and 3 for scissors: 2
Computer picked rock, Nathan picked paper.

Paper covers rock. You win.


Round 3.
Nathan, please enter your choice for this round.
1 for rock, 2 for paper, and 3 for scissors: 3
Computer picked rock, Nathan picked scissors.

Rock breaks scissors. I win.


Round 4.
Nathan, please enter your choice for this round.
1 for rock, 2 for paper, and 3 for scissors: 1
Computer picked paper, Nathan picked rock.

Paper covers rock. I win.


Round 5.
Nathan, please enter your choice for this round.
1 for rock, 2 for paper, and 3 for scissors: 2
Computer picked paper, Nathan picked paper.

This round is a draw.


Round 6.
Nathan, please enter your choice for this round.
1 for rock, 2 for paper, and 3 for scissors: 3
Computer picked paper, Nathan picked scissors.

Scissors cut paper. You win.


Round 7.
Nathan, please enter your choice for this round.
1 for rock, 2 for paper, and 3 for scissors: 1
Computer picked scissors, Nathan picked rock.

Rock breaks scissors. You win.


Round 8.
Nathan, please enter your choice for this round.
1 for rock, 2 for paper, and 3 for scissors: 2
Computer picked scissors, Nathan picked paper.

Scissors cut paper. I win.


Round 9.
Nathan, please enter your choice for this round.
1 for rock, 2 for paper, and 3 for scissors: 3
Computer picked scissors, Nathan picked scissors.

This round is a draw.


We played 9 games of Rock Paper Scissors.
The computer won 3 times.
Nathan won 3 times.
There were 3 draws.
We are evenly matched at this game.

Why don't take a shot at coding the program and report back with any problems you encounter. Don't just type your homework assignment up and expect someone to do it for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.