MINDTAPV2.0 JAVA PROGRAMMING 2021, 1TERM
MINDTAPV2.0 JAVA PROGRAMMING 2021, 1TERM
9th Edition
ISBN: 9780357505526
Author: FARRELL
Publisher: CENGAGE L
bartleby

Concept explainers

bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 8, Problem 12PE

a.

Explanation of Solution

Program:

File name: “DrugTests2.java

//Define a class named DrugTests2

public class DrugTests2

{

    //Define a main method

    public static void main(String[] args)

    {

        //Declare the variables and initialize the values

        int testedEmployee;

        int week;

        final int WEEKS = 52;

        final int EMPLOYEES = 30;

        int[] counts = new int[EMPLOYEES];

        int countNeverTested = 0;

        int x;

        /*For loop to be executed until a list of randomly

        selected employees who will be tested each

        week for the next 52 weeks*/

        for(week = 1; week <= WEEKS; ++week)

        {

            //Calculate the number of times each employee is selected

            testedEmployee = 1 + (int) (Math.random() * EMPLOYEES);

            //Print the result

            System.out.print("week " + week + " Emp # " +

            testedEmployee + "      ");

            //If remainder of week % 4 equals 0

            if(week % 4 == 0)

                //Print the result

                System.out.println();

                //Increment counts

                counts[testedEmployee - 1]++;

        }

        //For loop to be executed until x exceeds 30

        for(x = 0; x < EMPLOYEES; ++x)

        {

            //Print the result

System...

b.

Explanation of Solution

Program:

File name: “DrugTests3.java

//Define a class named DrugTests3

public class DrugTests3

{

    //Define a main method

    public static void main(String[] args)

    {

        //Declare the variables and initialize the values

        int testedEmployee;

        int week;

        final int WEEKS = 52;

        final int EMPLOYEES = 30;

        int[] counts = new int[EMPLOYEES];

        int countNeverTested = 0;

        int x;

        int previousEmployee = -1;

        /*For loop to be executed until a list of randomly

        selected employees who will be tested each

        week for the next 52 weeks*/

        for(week = 1; week <= WEEKS; ++week)

        {

/*Calculate the number of times each employee is selected*/

testedEmployee = 1 + (int) (Math.random() * EMPLOYEES);

            /*If an employee number is selected

            immediately after it was already selected*/

            if(testedEmployee == previousEmployee)

            {

                //Decrement week

                week--;

                //Print the result

                System.out.println("Employee #" + testedEmployee + " was selected two weeks in a row -- making new selection");

            }

            //Else

            else

            {

                //Print the result

                System.out.print("week " + week + " Emp # " +

                testedEmployee + "      ");

                //If remainder of week % 4 equals 0

                if(week % 4 == 0)

                    //Print the result

                    System...

Blurred answer
Students have asked these similar questions
We are considering the RSA encryption scheme. The involved numbers are small, so the communication is insecure.  Alice's public key (n,public_key) is (247,7). A code breaker manages to factories  247 = 13 x 19  Determine Alice's secret key. To solve the problem, you need not use the extended Euclid algorithm, but you may assume that her private key is one of the following numbers 31,35,55,59,77,89.
Consider the following Turing Machine (TM). Does the TM halt if it begins on the empty tape? If it halts, after how many steps? Does the TM halt if it begins on a tape that contains a single letter A followed by blanks? Justify your answer.
Pllleasassseee ssiiirrrr soolveee thissssss questionnnnnnn
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Python Tutorial #10; Math Functions in Python; Author: Art of Engineer;https://www.youtube.com/watch?v=OviXsGf4qmY;License: Standard YouTube License, CC-BY