Java Programming (MindTap Course List)
Java Programming (MindTap Course List)
9th Edition
ISBN: 9781337397070
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
Exercise docID document text docID document text 1 hot chocolate cocoa beans 7 sweet sugar 2345 9 cocoa ghana africa 8 sugar cane brazil beans harvest ghana 9 sweet sugar beet cocoa butter butter truffles sweet chocolate 10 sweet cake icing 11 cake black forest Clustering by k-means, with preprocessing tokenization, term weighting TFIDF. Manhattan Distance. Number of cluster is 2. Centroid docID 2 and docID 9.
Change the following code so that there is always at least one way to get from the left corner to the top right, but the labyrinth is still randomized. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. Take care that the player and the dragon cannot start off on walls. Also the dragon starts off from a randomly chosen position   public class Labyrinth {    private final int size;    private final Cell[][] grid;     public Labyrinth(int size) {        this.size = size;        this.grid = new Cell[size][size];        generateLabyrinth();    }     private void generateLabyrinth() {        Random rand = new Random();        for (int i = 0; i < size; i++) {            for (int j = 0; j < size; j++) {                // Randomly create walls and paths                grid[i][j] = new Cell(rand.nextBoolean());            }        }        // Ensure start and end are…
Change the following code so that it checks the following 3 conditions: 1. there is no space between each cells (imgs) 2. even if it is resized, the components wouldn't disappear 3. The GameGUI JPanel takes all the JFrame space, so that there shouldn't be extra space appearing in the frame other than the game.   Main():         Labyrinth labyrinth = new Labyrinth(10);         Player player = new Player(9, 0);        Dragon dragon = new Dragon(9, 9);         JFrame frame = new JFrame("Labyrinth Game");        GameGUI gui = new GameGUI(labyrinth, player, dragon);         frame.add(gui);        frame.setSize(600, 600);        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        frame.setVisible(true);   public class GameGUI extends JPanel {    private final Labyrinth labyrinth;    private final Player player;    private final Dragon dragon; //labyrinth, player, dragon are just public classes     private final ImageIcon playerIcon = new ImageIcon("data/images/player.png");…
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