97.5k views
3 votes
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: testedEmployee = 1 + (int) (Math.random() * 30); After each selection, display the number of the employee to test. Display four employee numbers on each line. It is important to note that if testing is random, some employees will be tested multiple times, and others might never be tested. Run the application several times until you are confident that the selection is random.

User Adriano P
by
4.6k points

1 Answer

1 vote

Answer:

Following are the program to this question:

import java.util.*; //import package

public class Main //defining class

{

public static void main(String[] args) //defining main method

{

int testedEmployee; //defining integer variable

for(int i = 1;i<=52;i++) //defining loop that counts from 1 to 52

{

testedEmployee = 1 + (int) (Math.random() * 30); //using random method that calculate and hold value

System.out.print(testedEmployee+"\t"); //print value

if(i%4 == 0)//defining codition thats checks value is divisiable by 4

{

System.out.println(); //print space

}

}

}

}

Output:

please find the attachment.

Step-by-step explanation:

In the given java program, a class Main is declared, inside the class, the main method is declared, in which an integer variable "testedEmployee", is declared, in the next line, the loop is declared, that can be described as follows:

  • Inside the loop, a variable "i" is declared, which starts from 1 and stop when its value is 52, inside the loop a random method is used, that calculates the random number and prints its value.
  • In the next step, a condition is defined, that check value is divisible 4 if this condition is true, it will print a single space.
Each week, the Pickering Trucking Company randomly selects one of its 30 employees-example-1
User Take
by
5.5k points