Question: Problem 3. TeamLeader Class In a particular factory, a team leader is an hourly paid production worker that leads a small team. In addition to

Problem 3.

TeamLeader Class

In a particular factory, a team leader is an hourly paid production worker that leads

a small team. In addition to hourly pay, team leaders earn a fixed monthly bonus.

Team leaders are required to attend a minimum number of hours of training per year.

Design a TeamLeader class that extends the ProductionWorker class you designed in

Programming Challenge 1.

The TeamLeader class should have fields for the monthly bonus amount, the required

number of training hours, and the number of training hours that the team leader has

Attended.

Write one or more constructors and the appropriate accessor and mutator methods for

The class.

If you have done the practice problems, test the program to make sure these parts works. If not, you can find the others solution in Unit 7 discussion board.

Add the TeamLeader class (Programming Challenge 3 on P698-699) to the program. The class includes:

A data members

Two constructors, one is default, another one is with parameters (to initialize data members in super classes and its own class)

Mutators and accessors for all data members.

Add the toString() method in all of the three classes.

Create your own exception classes:

An exception class, InvalidEmployeeNumber, used in the Employee class

An exception class, InvalidShift, used in the ProductionWorker class

An exception class, InvalidPayRate, used in the ProductionWorker class

An exception class, InvalidReqTrainingHours, used in the TeamLeader class

Modify the service classes so they throw (not handle) exceptions in methods when the following errors occur:

The Employee class should throw the InvalidEmployeeNumber when it receives an employee number that is not in the format XXX-L (each X is a digit within the range 0-9 and L is a letter within the range A-M).

The ProductWorker class should throw the InvalidShift when it receives an invalid shift.

The ProductWorker class should throw the InvalidPayRate when it receives a negative number for hourly pay rate.

The TeamLeader class should throw the InvalidReqTrainingHours when it receives a value that is less than 20 for the required number of training hours.

Notes:

One exception may be thrown in more than one method, e.g., in mutator and constructor

One method may throw multiple exceptions including these for its own class and for its super class. If the called method throws exception(s), the calling methods need to throw the exception(s).

Handle exceptions in the application class.

An incomplete application class is provided. To handle exceptions and test all exceptions in one application at the same time, complete the application class by defining two methods, createWorker() and createTeamLeader().

The main() method is completed (dont modify). It just calls two methods createWorker() and createTeamLeader() multiple times to test valid and invalid data.

Both methods have parameters. Inside each method, use the parameters as arguments in the constructor to instantiate an object (ProductionWorker in createWorker() and TeamLeader in createTeamLeader()), and handle your own exceptions.

To handle multiple exceptions, please use only ONE try block followed by MULTIPLE catch blocks.

Feel free to handle other exceptions.

Test your program. The screen shot is provided.

Here is the incomplete application class:

Invalid arguments in method calls are in RED. (You can test more invalid cases, such as 123, 12A-A, 123-AA, and so on, to make sure your validation is correct.)

DAY_SHIFT and NIGHT_SHIFT are public, static, and final int in the service class.

public class EmpDemo { public static void main(String[] args) { // Create a ProductionWorker object with valid data. System.out.println(" Creating a ProductionWorker object with valid data."); createWorker("John Smith", "123-A", "11-15-2009", ProductionWorker.DAY_SHIFT, 16.50); // Try to use an invalid employee number. System.out.println(" Attempting an invalid employee number..."); createWorker("Bill Dowman", "10001", "11-15-2010", ProductionWorker.DAY_SHIFT, 16.50); // Try to use an invalid shift number. System.out.println(" Attempting an invalid shift number..."); createWorker("Mary Johnson", "456-B", "11-15-2011", 66, 16.50); // Try to use a negative pay rate. System.out.println(" Attempting a negative pay rate..."); createWorker("James Sears", "789-C", "11-15-2012", ProductionWorker.NIGHT_SHIFT, -99.00); //Create a TeamLeader object with valid data. System.out.println(" Create a TeamLeader object with valid data."); createTeamLeader("John Doe", "777-D", "11-15-2013", ProductionWorker.DAY_SHIFT, 99.00, 120.00, 20, 12); // Try to use an invalid number of the training hour System.out.println(" Attempting an invalid number of hours..."); createTeamLeader("Steven Chang", "888-E", "11-15-2014", ProductionWorker.DAY_SHIFT, 99.00, 120.00, 15, 13); } //Create the createWorker() method here!

//Create the createTeamLeader() method here!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!