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

1.Question below the three ADT\'s public class Employee { private String name; p

ID: 3838837 • Letter: 1

Question

1.Question below the three ADT's

public class Employee {

   private String name;

   private int idNumber;

   private String department;

   private String position;

   /**
   * no argument constructor
   */
   public Employee() {
   }

   /**
   * argument constructor
   *
   * @param name
   *
   * @param idNumber
   *
   * @param department
   *
   * @param position
   *
   */

   public Employee(String name, int idNumber, String department, String position) {

       this.name = name;

       this.idNumber = idNumber;

       this.department = department;

       this.position = position;

   }

   // getters and setters

   /**
   *
   * @return name
   *
   */

   public String getName() {

       return name;

   }

   /**
   *
   * @return idNumber
   *
   */

   public int getIdNumber() {

       return idNumber;

   }

   /**
   *
   * @return department
   *
   */

   public String getDepartment() {

       return department;

   }

   /**
   *
   * @return position
   *
   */

   public String getPosition() {

       return position;

   }

   /**
   *
   * @param name
   *
   */

   public void setName(String name) {

       this.name = name;

   }

   /**
   *
   * @param idNumber
   *
   */

   public void setIdNumber(int idNumber) {

       this.idNumber = idNumber;

   }

   /**
   *
   * @param department
   *
   */

   public void setDepartment(String department) {

       this.department = department;

   }

   /**
   *
   * @param position
   *
   */

   public void setPosition(String position) {

       this.position = position;

   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   *
   */

   public String toString() {

       return "Name: " + name + ", ID: " + idNumber + ", Department: " + department + ", and Job Title: " + position;

   }

}

//////////

public class ProductionWorker extends Employee {
   int shift;
   double hourlyPayRate;

   /**
   * no argument constructor
   */
   public ProductionWorker() {
       super();
       shift = 0;
       hourlyPayRate = 0.0;
   }

   /**
   * argument constructor
   *
   * @param shift
   *
   * @param hourlyPayRate
   *
   */
   public ProductionWorker(String name, int idNumber, String department, String position, int shift,
           double hourlyPayRate) {
       super(name, idNumber, department, position);
       this.shift = shift;
       this.hourlyPayRate = hourlyPayRate;
   }

   // getters and setters
   /**
   *
   * @return shift
   *
   */
   public int getShift() {
       return shift;
   }

   /**
   *
   * @return hourlyPayRate
   *
   */
   public double getHourlyPayRate() {
       return hourlyPayRate;
   }

   /**
   *
   * @param set
   * shift
   *
   */
   public void setShift(int shift) {
       this.shift = shift;
   }

   /**
   *
   * @param set
   * hourlyPayRate
   *
   */
   public void setHourlyPayRate(double hourlyPayRate) {
       this.hourlyPayRate = hourlyPayRate;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   *
   */
   public String toString() {
       return super.toString() + "Shift: " + shift + ", Hourly Pay Rate: " + hourlyPayRate;
   }
}

/////

public class ShiftSupervisor extends Employee {
   double annualSalary;
   double bonus;

   /**
   * no argument constructor
   */
   public ShiftSupervisor() {
       super();
       annualSalary = 0;
       bonus = 0.0;
   }

   /**
   * argument constructor
   *
   * @param annualSalary
   *
   * @param bonus
   *
   */
   public ShiftSupervisor(String name, int idNumber, String department, String position, double annualSalary,
           double bonus) {
       super(name, idNumber, department, position);
       this.annualSalary = annualSalary;
       this.bonus = bonus;
   }

   // getters and setters
   /**
   *
   * @return annualSalary
   *
   */
   public double getAnnualSalary() {
       return annualSalary;
   }

   /**
   *
   * @return bonus
   *
   */
   public double getBonus() {
       return bonus;
   }

   /**
   *
   * @param shift
   *
   */
   public void setAnnualSalary(double annualSalary) {
       this.annualSalary = annualSalary;
   }

   /**
   *
   * @param bonus
   *
   */
   public void setBonus(double bonus) {
       this.bonus = bonus;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   *
   */
   public String toString() {
       return super.toString() + "AnnualSalary: " + annualSalary + ", Bonus: " + bonus;
   }
}

In a separate testing program, create ONE array that will hold 3 ProductionWorker objects and 3 ShiftSupervisor objects (think about what data type this array will have to be defined with). Create a menu to let users select the following functionality:

Display all worker names and job titles (i.e. Kevin --- Foreman)

Display all workers who receive an annual bonus

Display all workers on the night shift

Display all worker information

Do not use import java.util.ArrayList

Explanation / Answer

Hi, Please find my implemenation.

please let me know in case of any issue.

import java.util.ArrayList;

import java.util.Scanner;

public class TestEmployee {

   public static void displayNameTitle(ArrayList<Employee> emps){

       for(Employee e : emps){

           System.out.println(e.getName()+" --- "+e.getPosition());

       }

   }

   public static void displayBonusWorkers(ArrayList<Employee> emps){

       for(Employee e : emps){

           if(e instanceof ShiftSupervisor)

               System.out.println(e);

       }

   }

   public static void displayNightShift(ArrayList<Employee> emps){

       for(Employee e : emps){

           if(e instanceof ProductionWorker)

               if(((ProductionWorker) e).getShift() == 1)

                   System.out.println(e);

       }

   }

  

   public static void displayAll(ArrayList<Employee> emps){

       for(Employee e : emps){

           System.out.println(e);

       }

   }

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

       int option;

       ArrayList<Employee> employees = new ArrayList<>();

       // creating ProductionWorker and ShiftSupervisor Objects

       ProductionWorker p1 = new ProductionWorker("Pravesh Kuamr", 1, "Civil", "Manager", 0, 35.4);

       ProductionWorker p2 = new ProductionWorker("Mukes Kuamr", 2, "CSE", "Senior Manager", 0, 55.4);

       ProductionWorker p3 = new ProductionWorker("Alex Bob", 3, "Electrical", "Manager", 1, 40.4);

       ShiftSupervisor s1 = new ShiftSupervisor("Vikash R", 4, "IT", "Developer", 34234, 432);

       ShiftSupervisor s2 = new ShiftSupervisor("K L Rahul", 5, "IT", "DevOps", 1234, 100);

       ShiftSupervisor s3 = new ShiftSupervisor("Venta R", 6, "Mechinacl", "Technocian", 4354, 800);

       // adding all to array list

       employees.add(p1);

       employees.add(p2);

       employees.add(p3);

       employees.add(s1);

       employees.add(s2);

       employees.add(s3);

       while(true){

           System.out.println("1. Display all worker names and job titles");

           System.out.println("2. Display all workers who receive an annual bonus");

           System.out.println("3. Display all workers on the night shift");

           System.out.println("4. Display all worker information");

           System.out.println("5. Exit");

           option = sc.nextInt();

           if(option == 1){

               displayNameTitle(employees);

           }

           else if(option == 2){

               displayBonusWorkers(employees);

           }else if(option == 3)

               displayNightShift(employees);

           else if(option == 4)

               displayAll(employees);

           else if(option == 5)

               break;

           else

               System.out.println("Invalid option!!!");

       }

   }

}

/*

Sample run:

1. Display all worker names and job titles

2. Display all workers who receive an annual bonus

3. Display all workers on the night shift

4. Display all worker information

5. Exit

1

Pravesh Kuamr --- Manager

Mukes Kuamr --- Senior Manager

Alex Bob --- Manager

Vikash R --- Developer

K L Rahul --- DevOps

Venta R --- Technocian

1. Display all worker names and job titles

2. Display all workers who receive an annual bonus

3. Display all workers on the night shift

4. Display all worker information

5. Exit

4

Name: Pravesh Kuamr, ID: 1, Department: Civil, and Job Title: ManagerShift: 0, Hourly Pay Rate: 35.4

Name: Mukes Kuamr, ID: 2, Department: CSE, and Job Title: Senior ManagerShift: 0, Hourly Pay Rate: 55.4

Name: Alex Bob, ID: 3, Department: Electrical, and Job Title: ManagerShift: 1, Hourly Pay Rate: 40.4

Name: Vikash R, ID: 4, Department: IT, and Job Title: DeveloperAnnualSalary: 34234.0, Bonus: 432.0

Name: K L Rahul, ID: 5, Department: IT, and Job Title: DevOpsAnnualSalary: 1234.0, Bonus: 100.0

Name: Venta R, ID: 6, Department: Mechinacl, and Job Title: TechnocianAnnualSalary: 4354.0, Bonus: 800.0

1. Display all worker names and job titles

2. Display all workers who receive an annual bonus

3. Display all workers on the night shift

4. Display all worker information

5. Exit

3

Name: Alex Bob, ID: 3, Department: Electrical, and Job Title: ManagerShift: 1, Hourly Pay Rate: 40.4

1. Display all worker names and job titles

2. Display all workers who receive an annual bonus

3. Display all workers on the night shift

4. Display all worker information

5. Exit

2

Name: Vikash R, ID: 4, Department: IT, and Job Title: DeveloperAnnualSalary: 34234.0, Bonus: 432.0

Name: K L Rahul, ID: 5, Department: IT, and Job Title: DevOpsAnnualSalary: 1234.0, Bonus: 100.0

Name: Venta R, ID: 6, Department: Mechinacl, and Job Title: TechnocianAnnualSalary: 4354.0, Bonus: 800.0

1. Display all worker names and job titles

2. Display all workers who receive an annual bonus

3. Display all workers on the night shift

4. Display all worker information

5. Exit

5

*/