Java Reference
In-Depth Information
public static boolean
validSelection(
char
selection)
{
switch
(selection)
{
case
'R':
case
'r':
case
'P':
case
'p':
case
'S':
case
's':
return true
;
default
:
return false
;
}
}
This method uses the entered choice (
R
,
r
,
P
,
p
,
S
,or
s
) and returns the appropriate
object. The method has one parameter of the type
char
. It is a value-returning
method and returns a reference to a
RockPaperScissors
object.
The definition of the method
retrievePlay
is:
Method
retrieve
Play
public static
RockPaperScissors retrievePlay
(
char
selection)
{
RockPaperScissors obj = RockPaperScissors.ROCK;
switch
(selection)
{
case
'R':
case
'r':
obj = RockPaperScissors.ROCK;
break
;
case
'P':
case
'p':
obj = RockPaperScissors.PAPER;
break
;
case
'S':
case
's':
obj = RockPaperScissors.SCISSORS;
}
return
obj;
}
Search WWH ::
Custom Search