Java Reference
In-Depth Information
￿ displayRules : This method displays some brief information about the game
and its rules.
￿ validSelection : This method checks whether a player's selection is valid.
The only valid selections are R , r , P , p , S , and s .
￿ retrievePlay : This method uses the entered choice ( R , r , P , p , S ,or s ) and
returns the appropriate object.
￿ gameResult : This method outputs the players' choices and the winner of the
game.
￿ winningObject : This method determines and returns the winning object.
￿ displayResults : After the game is over, this method displays the final
results.
This method has no parameters. It consists only of output statements to explain the
game and rules of play. Essentially, this method's definition is:
Method
display
Rules
public static void displayRules()
{
System.out.println("Welcome to the game of Rock, "
+ "Paper, and Scissors.");
System.out.println("This is a game for two players. "
+ "For each game, each player \n"
+ "selects one of the "
+ "objects: Rock, Paper or "
+ "Scissors.");
System.out.println("The rules for winning the "
+ "game are: ");
System.out.println("1. If both players select the "
+ "same object, it is a tie.");
System.out.println("2. Rock crushes Scissors: The "
+ "player who selects Rock wins.");
System.out.println("3. Paper covers Rock: The "
+ "player who selects Paper wins.");
System.out.println("4. Scissors cuts Paper: The "
+ "player who selects Scissors "
+ "wins.");
System.out.println("Enter R or r to select Rock, "
+ "P or p to select Paper, \n"
+ "and S or s to select Scissors.");
}
Method
valid
Selection
This method checks whether a player's selection is valid. Let's use a switch state-
ment to check for the valid selection. The definition of this method is:
 
Search WWH ::




Custom Search