Demonstrate the ability to
u:\Lab4\ with three Java code files: Employee.java, ProductionWorker.java and Driver.java.String.matches method in Employee classDo Chapter 9, Programming Challenge 1: Employee and ProductionWorker Classes
u:\Lab4\.Driver.java should contain the main method Employee.java should contain the code for the superclass (note: code is provided below to copy and paste into your file. You do not need to modify this code)ProductionWorker.java should inherit from the Employee class. It should have fields to hold the following information:
Driver class to
Follow the sample sessions shown below:
Enter the name of the input file: employees.txt
Name: Ed Gellenbeck
Employee Number: 123-D
Hire Date: 10/2/2001
Shift: Day
Hourly Pay Rate: $12.50
Name: Fred Stanley
Employee Number: 345-A
Hire Date: 1/20/2000
Shift: Night
Hourly Pay Rate: $25.65
Name: Jim Schwing
Employee Number: 899-B
Hire Date: 05/12/2002
Shift: Day
Hourly Pay Rate: $100.33
You may use the following employees.txt input file:
Ed Gellenbeck 123-D 10/2/2001 1 12.50 Fred Stanley 345-A 1/20/2000 2 25.65 Jim Schwing 899-B 05/12/2002 1 100.33
Use the code below for your Employee class. You do not need to modify this code
public abstract class Employee
{
//Private instance variables
private String name;
private String number;
private String hireDate;
// No Args Constructor
public Employee()
{
name = "NO NAME";
number = "NO NUMBER";
hireDate = "NO HIRE DATE";
}
// Constructor
public Employee(String employeeName, String employeeNumber, String hireDate)
{
setEmployeeName(employeeName);
setEmployeeNumber(employeeNumber);
setHireDate(hireDate);
}
// Sets name to employeeName if legal, otherwise sets to "NO NAME"
public void setEmployeeName(String employeeName)
{
if (employeeName.matches("[a-zA-Z ]+"))
name = employeeName;
else
name = "NO NAME";
}
// Sets number to employeeNumber if legal, otherwise sets to "NO NUMBER"
public void setEmployeeNumber(String employeeNumber)
{
if (employeeNumber.matches("\\d{3}-[A-M]"))
number = employeeNumber;
else
number = "INVALID NUMBER";
}
// Sets hireDate to dateHired if legal, otherwise sets to "NO HIRE DATE"
public void setHireDate(String dateHired)
{
if (dateHired.matches("\\d\\d?/\\d\\d?/\\d\\d\\d\\d"))
hireDate = dateHired;
else
hireDate = "NO HIRE DATE";
}
// Returns the employee's name
public String getEmployeeName()
{
return name;
}
// Returns the employee's number
public String getEmployeeNumber()
{
return number;
}
// Returns the employee's hire date
public String getHireDate()
{
return hireDate;
}
// Returns the name, number and hire date
public String toString()
{
return "Name:\t\t" + name +
"\nEmployee Number:\t" + number +
"\nHire Date:\t\t" + hireDate;
}
}
ProductionWorker.java and Driver.java by the start of class on Wednesday.If you finish early, get yourself checked off first! As a programming challenge (not required but recommended):
Modify your program so that the
shift variable in ProductionWorker uses an enumerated type instead. If a value other than 1 or 2 is read from input, assign shift to the default value Shift.NonepayRate the default value 0.0 if the input value is in the incorrect format
public enum ShiftType {None, Day, Night}