Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

mployer and production worker. Design a class named Employer. The class should k

ID: 3673848 • Letter: M

Question

mployer and production worker. Design a class named Employer. The class should keep the following information in fields: .Employee name .Employee number in the format XXX-L where each X is a digit within the range 0-9 and the L is a letter withim the range A-M .Hire date write one or more constructor and the appropriate accessor and mutator methodes for the class. Next, write a class name ProductionWorker that inherits from the employer class. The production Worker class should have field to hold the following informations: .Shift (an integer) .Hourly pay rate (a double) The work day is dividedeinto two shifts: day and night. The shift field will be an integer value representing the shift that the employer works. The day shift is shift1 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 a ProductionWorker object.

Explanation / Answer

WorkDemo.java

// create class
public class WorkDemo
{
   public static void main(String args[])
   {

   // create object and passing parameters
   ProductionWorker employee1 = new ProductionWorker("John Smith", "11-15-2005" ,123 ,'A' , 1, 16.50);
   ProductionWorker employee2 = new ProductionWorker();

   // calling onjects of employee class
   employee2.setName("Joan Jones");
   employee2.setEmployeeNum(222);
   employee2.setEmployeeChar('L');
   employee2.setHireDate("12-12-2005");
   employee2.setShift(2);
   employee2.setHourlyPayRate(18.50);

   // display details of employees
   System.out.println(employee1);
   System.out.println(employee2);
   }
}


Employeer.java

public class Employee
{
   // declare local variables
   private String name, hireDate;
   private int employeeNum;
   private char employeeChar;
   private boolean validation;

   // constructor
   public Employee()
   {
       name = "";
       hireDate = "";
       employeeNum = 0;
       employeeChar = '*';
       validation = true;
   }

   //constructor with employee
   public Employee(String name, String hireDate, int employeeNum, char employeeChar)
   {
       setName(name);
       setHireDate(hireDate);
       setEmployeeNum(employeeNum);
       setEmployeeChar(employeeChar);
       validation = true;
   }

   // set name of employee
   public void setName(String name)
   {
       this.name = name;
   }

   public void setHireDate(String hireDate)
   {
       this.hireDate = hireDate;
   }

   // set emplyee number
   public void setEmployeeNum(int employeeNum)
   {
       this.employeeNum = employeeNum;
   }

  
   public void setEmployeeChar(char employeeChar)
   {
       this.employeeChar = employeeChar;
   }

   // get name of employee
   public String getName()
   {
       return name;
   }

   public String getHireDate()
   {
       return hireDate;
   }

   public int getEmployeeNum()
   {
       return employeeNum;
   }

   public char getEmployeeChar()
   {
       return employeeChar;
   }

   public boolean isValidEmpNum(int employeeNum, char employeeChar)
   {
       if(employeeNum < 0 || employeeNum > 1000)
           validation = false;

       if(employeeChar < 'A' || employeeChar > 'M')
            validation = false;

            return validation;
    }

   // display result
   public String toString()
   {
       return("Name: " + name + " " + "ID: " + employeeNum + "-" + employeeChar + " " + "Hire Date: " + hireDate);
   }
}


ProductionWorker.java

public class ProductionWorker extends Employee
{
   // declare variables
   private int shift;
   private double hourlyPayRate;

   // constructor
   public ProductionWorker()
   {
       super();
       shift = 1;
       hourlyPayRate = 0;
   }

   // constructor with parameters
   public ProductionWorker(String name, String hireDate, int employeeNum, char employeeChar, int shift, double hourlyPayRate)
   {
       super(name, hireDate, employeeNum, employeeChar);
       setShift(shift);
       setHourlyPayRate(hourlyPayRate);
   }

   // setter
   public void setShift(int shift)
   {
       this.shift = shift;
   }

   public void setHourlyPayRate(double hourlyPayRate)
   {
       this.hourlyPayRate = hourlyPayRate;
   }

   // getter
   public int getShift()
   {
       return shift;
   }

   public double getHourlyPayRate()
   {
       return hourlyPayRate;
    }

   //display result
    public String toString()
    {
       if(shift == 1)
       return(super.toString() + " " + "Day Shift " + "Pay Rate per Hour: " + String.format("$%.2f%n%n", hourlyPayRate));

       else
       return(super.toString() + " " + "Night Shift " + "Pay Rate per Hour: " + String.format("$%.2f%n%n", hourlyPayRate));
   }
}

output

Name: John Smith                                                                                                                                            
ID: 123-A                                                                                                                                                   
Hire Date: 11-15-2005                                                                                                                                       
Day Shift                                                                                                                                                   
Pay Rate per Hour: $16.50                                                                                                                                   
                                                                                                                                                            
                                                                                                                                                            
Name: Joan Jones                                                                                                                                            
ID: 222-L                                                                                                                                                   
Hire Date: 12-12-2005                                                                                                                                       
Night Shift                                                                                                                                                 
Pay Rate per Hour: $18.50