Each week, the Pickering Trucking Company randomly selects one of its 30 employees to take a drug test. Write an application that determines which employee will be selected each week for the next 52 weeks. Use the Math.random() function explained in Appendix D to generate an employee number between 1 and 30; you use a statement similar to:

Respuesta :

Answer:

In Java:

import java.util.Random;

public class Main{

public static void main(String args []){

  int Employee;

  for(int weeks = 1;weeks<=52;weeks++){

    Employee = 1 + (int)(Math.random() * 30);

    System.out.println("Week "+weeks+" selected employee: "+Employee);

  }

}

}

Step-by-step explanation:

This imports the Random package into the program

import java.util.Random;

public class Main{

public static void main(String args []){

Declare employee as integer (represents employee 1 to 30)

  int Employee;

Iterate from week 1 to 52

  for(int weeks = 1;weeks<=52;weeks++){

Randomly select an employee from 1 to 30 (inclusive)

    Employee = 1 + (int)(Math.random() * 30);

Print the selected employee

    System.out.println("Week "+weeks+" selected employee: "+Employee);

  }

}

}

ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE