Concept explainers
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...
Trending nowThis is a popular solution!
Chapter 8 Solutions
Mindtap Computing, 1 Term (6 Months) Printed Access Card For Farrell’s Java Programming, 8th
- JAVA Problem description:You are to write a program called Seasons that prompts the user for a month and day and displays the season in which that date occurs. For reference, we will use the following date cutoffs for the various seasons: Winter December 21 – March 19 Spring March 20th – June 20th Summer June 21st – September 20th Fall September 21st – December 20th Data Validation For this program, you'll write a specific method to perform data validation based on the month and day entered. More specifically: Month – the month entered must be a valid month of the year (January – December). Day – the day entered must be a valid day for that month: January, March, May, July, August, October, December have 1-31 days. April, June, September, November have 1-30 days. February has 1-28 days (do not worry about leap years) Required program decomposition String getMonth(Scanner console) This method is called from the main method and should prompt for the month as a string…arrow_forwardPlease help me with the question on the picturearrow_forwardin java pls: You have been asked to produce a report for a hardware store The name for each item is widget with the word designating the number of the widget. There are ten widgets in all. Your program will ask the user for the range of the cost for items, range of the price of the items in doubles. The range for the quantity in stock will be between 0 and 9999 as an int. Your program will randomly generate the cost of the items, price of the items the number in stock for this sample report based upon the ranges entered. Make sure the price of the item is greater than the cost. Profit is calculated as (price- cost) * in stock. Any time quantity falls below 25 the reorder column will display Yes, otherwise it will display No. Your chart will generate data for ten items and the chart will look like the one below. Part QuantityName Cost Price in Stock…arrow_forward
- iuierarrow_forwardReza Enterprises sells tickets for buses, tours, and other travel services. Because Reza frequently mistypes long ticket numbers, Reza Enterprises has asked his students to write an application that shows if a ticket is invalid. Your application/program tellsthe ticket agent to enter a six-digit ticket number. Ticket numbers are designed so that if you lose the last digit of the number, then divide by 7, the remainder of the division is exactly the same to the last dropped digit. This process is shown below: Step 1: Enter the ticket number; for example 123454 Step 2: Remove the last digit, leaving 12345 Step 3: Determine the remainder when the ticket number from step 2 is divided by 7. In this case, 12345 divided by 7 leaves a remainder of 4. Step 4: Display a message to the ticket agent indicating whether the ticket number is valid or not.. Test your application with the following ticket numbers: - 123454; is a valid ticket number - 147103; is a valid ticket number -…arrow_forwardThis program uses Java. You will be making a general class that will be called “GeneralBusiness”. This class must have the following methods: selectSalesTax() – This method will read in a file “stateTaxInfo.txt” that has the name of a state and the tax percentage (decimal form) for that state and save them to the given arrays. It will then print a menu for the user to choose the state that the business is in and set the variables to hold the values. getCustomerName() – This method will prompt the user for the name of the person using the program calcSalesTax() – This method will be sent a subtotal and calculate the sales tax outputReceipt() – This method will output a generic receipt as follows: Subtotal $37.50 Sales Tax $2.44 Total $39.94 outputMenu() - This method will receive the number of items and output a generic menu as follows: Item 1 Item 2 Item 3 Item 4 must have the following variables: stateNames - array saleTax – array saleTaxAmount theStateName subtotal total firstName…arrow_forward
- THIS IS JAVA PROGRAMMING When the user enters 4 at the menu prompt, your program will access all objects in the array to calculate and display only the largest number of coin denomination, and the total number of coins for the largest denomination. If there are more than one coin denominations having equal amount, you will need to list down all of them. After processing the output for menu option 4, the menu is re-displayed. For example: Customer: Jane 65 cent Change: 50 cent: 1 10 cent: 1 5 cent: 1 Customer: John 75 cent Change: 50 cent: 1 20 cent: 1 5 cent: 1 Menu option 4 should return as follows.arrow_forwardA Java Practical Assignments.pdf - Adobe Acrobat Pro DC (32-bit) File Edit View E-Sign Window Help Home Tools Java Practical Assig. x Sign In 1 /1 139% Java Practical Assignments 1. Write an application that throws and catches an ArithmeticException when you attempt to take the square root of a negative value. Prompt the user for an input value and try the Math.sqrt() method on it. The application either displays the square root or catches the thrown Exception and displays an appropriate message. 2. Create a program that allows a user to input customer records (ID number, first name, last name, and balance owed) and save each record to a file. 3. Write an application for Limpopo's Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as R250, R220, R150, or R50, accordingly. Display an error message if the…arrow_forwardJava Your program will read in a credit card number and expiration date from the user and validate the data. The program will continue to ask for user input until a valid number and date are entered. The rules for what is valid are specified below. readYear() and readMonth(int) methods Complete the readYear() and readMonth(int) methods. These methods ask the user to input the expiration year and month of their credit card. Each method should contain a loop inside the method so the code repeats until a valid month or year is entered by the user. If the user enters an invalid year or month, print an error message and ask them to try again. The readMonth(int) method reads in the month as a number. A valid month is any number between 1 and 12 (inclusive). A valid year is 2022 or later. readCreditCardNumber() method Complete the readCreditCardNumber() method. This method asks the user to input their credit card number. This method should contain a loop so the code repeats until a valid…arrow_forward
- Need help coding in Java Create an application that contains an enumeration that represents the days of the week. Display a list of the days, and then prompt the user for a day. Display business hours for the chosen day. Assume that the business is open from 11 - 5 on Sunday, 9 - 9 on weekdays, and 10 - 6 on Saturday.arrow_forwardPlease help me with the question on the picturearrow_forward1. 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 and return 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. s = ½ gt² where s = distance in meters g=9.8, and t = time in seconds SEC 1 PAVASAWNI 2 4 5 6 7 8 9 10 METERS 4.9 19.6 44.1 78.4 122.5 176.4 240.1 313.6 396.9 490.0 FEET 16.1 64.3 144.7 257.2 401.9 578.7 787.7 1028.9 1302.2 1607.6arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT