EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
8th Edition
ISBN: 9781305480537
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
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
You are playing a game that has two dice – one die has 6 sides numbered 1 through 6 and the second die has 8 sides numbered 1 through 8. A turn involves rolling both die together. Write Java code to play 1,000 turns and keep track of the sum of the two dice in each roll i.e, (2 through 14). When all 1,000 turns have been completed, print a formatted table showing the value of the sum of the two dice (2 through 14) and the number of times that value occurred.
**THE CODE SHOULD BE IN JAVA** Write an application that allows a user to enter any number of student quiz scores, as integers, until the user enters 99. If the score entered is less than 0 or more than 10, display Score must be between 10 and 0 and do not use the score. After all the scores have been entered, display the number of valid scores entered, the highest score, the lowest score, and the arithmetic average. An example of the program is shown below: Enter a score >> 6 Enter another score or 99 to quit >> 7 Enter another score or 99 to quit >> 9 Enter another score or 99 to quit >> 7 Enter another score or 99 to quit >> 99 4 valid scores were entered Highest was 9 Lowest was 6 Average was 7.25
Write an application that allows a user to enter any number of student quiz scores, as integers, until the user enters 99. If the score entered is less than 0 or more than 10, display Score must be between 10 and 0 and do not use the score. After all the scores have been entered, display the number of valid scores entered, the highest score, the lowest score, and the arithmetic average.
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
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Python Tutorial #10; Math Functions in Python; Author: Art of Engineer;https://www.youtube.com/watch?v=OviXsGf4qmY;License: Standard YouTube License, CC-BY