Employee and ProductionWorker Classes Design a class named Employee . The class
ID: 3535937 • Letter: E
Question
Employee and ProductionWorker Classes
Design a class named Employee. The class should keep the following information in fields:
Write one or more constructors and the appropriate accessor and mutator methods for the class.
Next, write a class named ProductionWorker that extends the Employee class. TheProductionWorker class should have fields to hold the following information:
The workday is divided into two shifts: day and night. The shift field will be an integer value representing the shift that the employee works. The day shift is shift 1 and the night shift is shift 2. Write one or more constructors and the appropriate accessor and mutator methods for the class. Demonstrate the classes by writing a program that uses aProductionWorker object.
Modify the Employee and ProductionWorker classes so they throw exceptions when the following errors occur:
Write a test program, WorkerDemo.java, that demonstrates how each of these exception conditions works.
Explanation / Answer
public class Employee { //private fields public String name; public String number; public String hireDate; private boolean validNumber= false; //constructor method public Employee(String n, String num, String hd) { name = n; number = num; hireDate = hd; } public String getName() { return name; } public String getNumber() { while (validNumber = false) { if (number.length()!=5) { System.out.println("Invalid employee number, please try again."); } else if (((!Character.isDigit(number.charAt(0))) || ((!Character.isDigit(number.charAt(1)))) || ((!Character.isDigit(number.charAt(2)))) || (number.charAt(3) !='-') || ((!Character.isDigit(number.charAt(4)))) || (!(number.charAt(4)>= 'A' && number.charAt(4)= 'A' && number.charAt(4)Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.