Question
Create a ShiftSupervisor.java and a ShiftSupervisorDemo.java. ShiftSupervisor Class: In a particular factory, a shift supervisor is a salaried employee who supervises a shift. In addition
Create a ShiftSupervisor.java and a ShiftSupervisorDemo.java. ShiftSupervisor Class: In a particular factory, a shift supervisor is a salaried employee who supervises a shift. In addition to a salary, the shift supervisor earns a yearly bonus when his or her shift meets production goals. Design a ShiftSupervisor class that extends the Employee.java class you can download by clicking on the file name. The ShiftSupervisor class should have a field that holds the annual salary and a field that holds the annual production bonus that a shift supervisor has earned. Write one or more constructors and the appropriate accessor and mutator methods for the class. Demonstrate the class by writing a program, ShiftSupervisorDemo.java for instance, that uses a ShiftSupervisor object. TIP: Your ShiftSupervisor class should inherit from the Employee class which you have downloaded. You will have two private fields: salary and bonus in you ShiftSupervisor class. They are both Double data type. You will also have constructors in your ShiftSupervisorclass that will call its super, Employee class's constructors accordingly. You may have two constructors, one with parameters, one without. Your ShiftSupervisorDemo.java will have a main() method. Some ShiftSupervisor objects will be created in this main() method. You may want to display these new created ShiftSupervisor object's information.
Employee.java /** The Employee class stores data about an employee for the ShiftSupervisor Class programming challenge. */ public class Employee { private String name; // Employee name private String employeeNumber; // Employee number private String hireDate; // Employee hire date /** This constructor initializes an object with a name, employee number, and hire date. @param n The employee's name. @param num The employee's number. @param date The employee's hire date. */ public Employee(String n, String num, String date) { name = n; setEmployeeNumber(num); hireDate = date; } /** The no-arg constructor initializes an object with null strings for name, employee number, and hire date. */ public Employee() { name = ""; employeeNumber = ""; hireDate = ""; } /** The setName method sets the employee's name. @param n The employee's name. */ public void setName(String n) { name = n; } /** The setEmployeeNumber method sets the employee's number. @param e The employee's number. */ public void setEmployeeNumber(String e) { if (isValidEmpNum(e)) employeeNumber = e; else employeeNumber = ""; } /** The setHireDate method sets the employee's hire date. @param h The employee's hire date. */ public void setHireDate(String h) { hireDate = h; } /** The getName method returns the employee's name. @return The employee's name. */ public String getName() { return name; } /** The getEmployeeNumber method returns the employee's number. @return The employee's number. */ public String getEmployeeNumber() { return employeeNumber; } /** The getHireDate method returns the employee's hire date. @return The employee's hire date. */ public String getHireDate() { return hireDate; } /** isValidEmpNum is a private method that determines whether a string is a valid employee number. @param e The string containing an employee number. @return true if e references a valid ID number, false otherwise. */ private boolean isValidEmpNum(String e) { boolean status = true; if (e.length() != 5) status = false; else { if ((!Character.isDigit(e.charAt(0))) || (!Character.isDigit(e.charAt(1))) || (!Character.isDigit(e.charAt(2))) || (e.charAt(3) != '-') || (!Character.isLetter(e.charAt(4)))) status = false; } return status; } /** toString method @return A reference to a String representation of the object. */ public String toString() { String str = "Name: " + name + " Employee Number: "; if (employeeNumber == "") str += "INVALID EMPLOYEE NUMBER"; else str += employeeNumber; str += (" Hire Date: " + hireDate); return str; } } |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started