Skip to main content

Section 3.14 Assessment: Call a Method of Random

Subgoals for Calling a Method.

  1. Classify method as static method or instance method
    1. If static, use the class name
    2. If instance, must have or create an instance
  2. Write (instance / class) dot method name and ( )
  3. Determine whether parameter(s) are appropriate
    1. Number of parameters passed must match method declaration
    2. Data types of parameters passed must match method declaration (or be assignable)
  4. Determine what the method will return (if anything: data type, void, print, change state of object) and where it will be stored (nowhere, somewhere)
  5. Evaluate right hand side of assignment (if there is one). Value is dependent on method’s purpose

Exercises Exercises

    1.

      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.
    • Random
    • nextInt
    • new
    • 5
    • 50

    2.

      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.
    • Random
    • nextInt
    • new
    • 5
    • 46

    3.

      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.
    • Random
    • nextInt
    • new
    • 5
    • 45

    4.

      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.
    • Random
    • nextInt
    • new
    • 5
    • 55

    5.

      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.
    • nextInt
    • 55
    • 50
    • 45
    • 46

    6.

      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.
    • nextInt
    • 0
    • 5
    • 50
    • 45
You have attempted of activities on this page.