Skip to main content\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 4.11 ObjUse-WE5-P1
Subgoals for Calling a Method.
-
Classify method as
static
method or
instance
method
-
If
static
, use the class name
-
If
instance
, must have or create an instance
-
Write (instance / class) dot method name and ( )
-
Determine whether parameter(s) are appropriate
-
Number of parameters passed must match method declaration
-
Data types of parameters passed must be compatible with method declaration
-
Determine what the method will return and where it will be stored
-
Evaluate right hand side of assignment. Value is dependent on method’s purpose
Subsection 4.11.1
Exercises Exercises
1.
Q14: What number goes in the blank so that a random value between 0 and 5 will be generated?
Random random = new Random();
int die = random.nextInt(_______);
2.
Q15: Click on the method calls of the Random instance in the following code
Random rand = new Random();
int flippedCoin = rand.nextInt(2);
int playingCard = rand.nextInt(52);
3.
Q16: Click on the parameters passed to method calls of the Random instance in the following code
Random rand = new Random();
int flippedCoin = rand.nextInt(2);
int playingCard = rand.nextInt(52);
You have attempted
of
activities on this page.