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
JAVA PROGRAM(LL)+MINDTAP (1 TERM) V2.0
- Create an application for generating lottery tickets of random numbers. Each lottery ticket has a fixed count of numbers to be played with each number selected being within a given range. For example, when the range of numbers is 1 through 100, and 5 numbers are to be played, the lottery ticket will be composed of 5 unique values between 1 and 100. The values are selected at random. The main function is responsible for obtaining the upper range of the numbers and the count of numbers to be played from the end user. The count of numbers must be less than the upper range. The main function will call the generateLotto function to generate the lottery ticket and then call the displayTicket function to display the resulting lottery ticket. Any number of lottery tickets may be generated. The generateLotto function should accept two parameters. The first should be the upper range for the numbers while the second parameter represents a count of the numbers to be played. For example,…arrow_forwardCreate an application for generating lottery tickets of random numbers. Each lottery ticket has a fixed count of numbers to be played with each number selected being within a given range. For example, when the range of numbers is 1 through 100, and 5 numbers are to be played, the lottery ticket will be composed of 5 unique values between 1 and 100. The values are selected at random. The main function is responsible for obtaining the upper range of the numbers and the count of numbers to be played from the end user. The count of numbers must be less than the upper range. The main function will call the generateLotto function to generate the lottery ticket and then call the displayTicket function to display the resulting lottery ticket. Any number of lottery tickets may be generated. The generateLotto function should accept two parameters. The first should be the upper range for the numbers while the second parameter represents a count of the numbers to be played. For example,…arrow_forwardCreate an application for generating lottery tickets of random numbers. Each lottery ticket has a fixed count of numbers to be played with each number selected being within a given range. For example, when the range of numbers is 1 through 100, and 5 numbers are to be played, the lottery ticket will be composed of 5 unique values between 1 and 100. The values are selected at random. The main function is responsible for obtaining the upper range of the numbers and the count of numbers to be played from the end user. The count of numbers must be less than the upper range. The main function will call the generateLotto function to generate the lottery ticket and then call the displayTicket function to display the resulting lottery ticket. Any number of lottery tickets may be generated. The generateLotto function should accept two parameters. The first should be the upper range for the numbers while the second parameter represents a count of the numbers to be played. For example,…arrow_forward
- 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_forwardTHIS 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_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_forward
- Microsoft Visual C# 7th edition. need help, please. Thanks In previous chapters, you created applications for Marshall’s Murals. Now, modify the version of the MarshallsRevenue program created in Chapter 5 so that after mural data entry is complete, the user is prompted for the appropriate number of customer names for both the interior and exterior murals and a code for each that indicates the mural style: L for landscape S for seascape A for abstract C for children’s O for other When a code is invalid, re-prompt the user for a valid code continuously. For example, if Y is input, output Y is not a valid code, and re-prompt the user until a valid code is entered. After data entry is complete, display a count of each type of mural. For example the output should be in the following format with the correct number next to each mural type: The interior murals scheduled are: Landscape 1 Seascape 2 Abstract 1 Children's 3 Other 9 The exterior murals scheduled are: Landscape 4 Seascape 0…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_forwardNeed 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_forward
- A 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_forwardIn java A Carpet Company has asked you to write an application that calculates the price of carpeting for rectangular rooms in a building. To calculate the price, you multiply the area of the floor (width * length) by the price per square foot of carpet. For example, the area of floor that is 12 feet long and 10 feet wide is 120 square feet. To cover that floor with carpet that costs 300 per square foot would cost (12 * 10 * 300 = 36000.) First, you should create a class named RoomDimension that has two attributes: one for the length of the room and one for the width. Provide getters/setters, parameterized constructor and a toString method. The RoomDimension class should also have a member function that returns the area of the room. Once you have written the class, use in a test application that asks the user to enter the number of rooms in building create array of that size, then ask user to enter dimensions for each room, also ask user for price per square foot of the desired…arrow_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