EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
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
Use Java programming language Write a program that asks the user to enter 5 test grades (use an array to store them). Output the grades entered, the lowest and highest grade, the average grade, how many grades are above the average and how many are below and the letter grade for the average grade. Create a method that returns the lowest grade. Create a method that returns the highest grade. Create a method that returns the average grade. Create a method that returns how many grades were above the average. Create a method that returns how many grades were below the average. Create a method that returns the letter grade of the average (90-100 – A, 80-89 – B, 70-79 – C, < 70 – F)
Trainers at Tom's Athletic Club are encouraged to enroll new members.  Write an application that extracts the names of Trainers and groups them based on the number of new members each trainer has enrolled this year.  Output is the number of trainers who have enrolled 0 to 5 members, 6 to 12 members, 13 to 20 members, and more than 20 members.  Give their names as well as the number of members they have enrolled.    Use this list of trainers: {"Jake Butt", "Ziggy Hood", "Hroniss Grasu", "Vontaze Burfict", "Jaquiski Tartt","Ndamukong Suh", "Thurston Armbrister", "Captain Munnerlyn", "Barkevious Mingo", "Ha Ha Clinton-Dix","Mister Alexander", "BenJarvus Green-Ellis", "Richie Incognito", "Champ Bailey", "Captain Munnerlyn","Mike Kafka", "Ras-I Dowling", "Bryan Anger", "D'Brickashaw Ferguson", "Rex Hadnot","Sage Rosenfels", "Robert Griffin III", "Sav Rocca", "Chad Ochocinco", "Brett Rypien"} Use this list of the number of members each trainer has enrolled: {3, 9, 13, 26, 23,19, 15, 13, 17,…
USING JAVA:  Write a program that analyzes an object falling for 10 seconds. It should contain main and two additional methods. One of the additional methods should return the distance an object falls in meters when passed the current second as an argument. See the formula needed below. The third method should convert meters to feet. You can look up the conversion factor needed online. The main method should use one loop to call the other methods and generate a table as shown below. The table should be displayed in formatted columns with decimals as shown.
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
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
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