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
ExercisesExercises
1.
Q1: Which of the following will correctly declare and instantiate a new variable to generate Random values?
Random rand = rand();
Random rand = rand(50);
Random rand = new Random();
Random rand = new Random(50);
2.
Q2: Fill in the blanks for the following code to create a Random number between 1 and 50.
// assume you have declared and initialized variable rand to
// be an instance of the Random class
_______ result = rand._______ ( __________ ) + ___________ ;
D A B C
Fill in blank A.
rand
nextInt
nextDouble
new
next
3.
Q3: Fill in the blanks for the following code to create a Random number between 1 and 50.
// assume you have declared and initialized variable rand to
// be an instance of the Random class
_______ result = rand._______ ( __________ ) + ___________ ;
D A B C
Fill in blank B.
nothing goes here
1
50
49
4.
Q4: Fill in the blanks for the following code to create a Random number between 1 and 50.
// assume you have declared and initialized variable rand to
// be an instance of the Random class
_______ result = rand._______ ( __________ ) + ___________ ;
D A B C
Fill in blank C.
0
1
50
49
5.
Q5: Fill in the blanks for the following code to create a Random number between 1 and 50.
// assume you have declared and initialized variable rand to
// be an instance of the Random class
_______ result = rand._______ ( __________ ) + ___________ ;
D A B C