Java Programming (MindTap Course List)
Java Programming (MindTap Course List)
8th Edition
ISBN: 9781285856919
Author: Joyce Farrell
Publisher: Cengage Learning
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)
Travel Tickets Company sells tickets for airlines, tours, and other travel-related services. Because ticket agents frequently mistype long ticket numbers, Travel Tickets has asked you to write an application that indicates invalid ticket number entries. The class prompts a ticket agent to enter a six-digit ticket number. Ticket numbers are designed so that if you drop the last digit of the number, then divide the number by 7, the remainder of the division will be identical to the last dropped digit. Accept the ticket number from the agent and verify whether it is a valid number. Test the application with the following ticket numbers: . 123454; the comparison should evaluate to true . 147103; the comparison should evaluate to true . 154123; the comparison should evaluate to false Save the program as TicketNumber.java.
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