2.8. Assessment: Call a Method of Random¶
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 match method declaration (or be assignable)
Determine what the method will return (if anything: data type, void, print, change state of object) and where it will be stored (nowhere, somewhere)
Evaluate right hand side (RHS) of assignment (if there is one). Value is dependent on method’s purpose
- Random
- nextInt
- new
- 5
- 50
- Random
- nextInt
- new
- 5
- 46
- Random
- nextInt
- new
- 5
- 45
- Random
- nextInt
- new
- 5
- 55
- nextInt
- 55
- 50
- 45
- 46
- nextInt
- 0
- 5
- 50
- 45
Q1: Fill in the blanks for the following code, if the purpose of the code is to create a new Random number bwetween 5 and 50.
___A___ answer = ___B___ ___C___();
System.out.println(answer.___D___(___E___)+___F___)
Fill in blank A.
Q2: Fill in the blanks for the following code, if the purpose of the code is to create a new Random number bwetween 5 and 50.
___A___ answer = ___B___ ___C___();
System.out.println(answer.___D___(___E___)+___F___)
Fill in blank B.
Q3: Fill in the blanks for the following code, if the purpose of the code is to create a new Random number bwetween 5 and 50.
___A___ answer = ___B___ ___C___();
System.out.println(answer.___D___(___E___)+___F___)
Fill in blank C.
Q4: Fill in the blanks for the following code, if the purpose of the code is to create a new Random number bwetween 5 and 50.
___A___ answer = ___B___ ___C___();
System.out.println(answer.___D___(___E___)+___F___)
Fill in blank D.
Q5: Fill in the blanks for the following code, if the purpose of the code is to create a new Random number bwetween 5 and 50.
___A___ answer = ___B___ ___C___();
System.out.println(answer.___D___(___E___)+___F___)
Fill in blank E.
Q6: Fill in the blanks for the following code, if the purpose of the code is to create a new Random number bwetween 5 and 50.
___A___ answer = ___B___ ___C___();
System.out.println(answer.___D___(___E___)+___F___)
Fill in blank F.