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

JAVA CODE In a particular factory, a shift supervisor is a salaried employee who

ID: 2247076 • Letter: J

Question

JAVA CODE

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 ShiftSupervisor class that will call its super, Employee class's constructors accordingly. You may have tow 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 ma want to display these new created ShiftSupervisor object's information.

This is the Employee file:

Explanation / Answer

Note : Could you please check the output .If you required any changes Just intimate.I will modify it.Thank You.

______________

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;

}

}

_________________

ShiftSupervisor.java

public class ShiftSupervisor extends Employee {
// Declaring instance variables
private double salary;
private double bonus;

// Zero argumented constructor
public ShiftSupervisor() {

}

// Parameterized constructor
public ShiftSupervisor(String n, String num, String date, double salary,
double bonus) {
super(n, num, date);
this.salary = salary;
this.bonus = bonus;
}

// getters and setters
public double getSalary() {
return salary;
}

public void setSalary(double salary) {
this.salary = salary;
}

public double getBonus() {
return bonus;
}

public void setBonus(double bonus) {
this.bonus = bonus;
}

// toString method is used to display the contents of an object inside it
@Override
public String toString() {
return super.toString() + " salary = " + salary + " bonus = " + bonus;
}

}

_____________________

ShiftSupervisorDemo.java

import java.util.Scanner;

public class ShiftSupervisorDemo {

public static void main(String[] args) {

//Declaring variables
String name, empNo, date;
double sal, bonus;

//Scanner object is used to get the inputs entered by the user
Scanner sc = new Scanner(System.in);

//Getting the inputs entered by the user
System.out.print("Enter Employee Name :");
name = sc.nextLine();

System.out.print("Enter Employee No :");
empNo = sc.next();

System.out.print("Enter Joining date :");
date = sc.next();

System.out.print("Enter Salary :");
sal = sc.nextDouble();

System.out.print("Enter Bonus Amount :");
bonus = sc.nextDouble();

//Creating an Shift Supervisor class Object by passing user entered inputs as arguments.
ShiftSupervisor sv = new ShiftSupervisor(name, empNo, date, sal, bonus);

//Displaying the Shift Supervisor Info
System.out.println(":: Displaying Shift Supervisor Details ::");
System.out.println(sv.toString());

}

}

__________________

Output:

Enter Employee Name :Kane Williams
Enter Employee No :123-H
Enter Joining date :12-08-2012
Enter Salary :450000
Enter Bonus Amount :50000
:: Displaying Shift Supervisor Details ::
Name: Kane Williams
Employee Number: 123-H
Hire Date: 12-08-2012
salary = 450000.0
bonus = 50000.0

______________Thank You