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

Design a class named Employee. The class should keep the following information i

ID: 3837333 • Letter: D

Question

Design a class named Employee. 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 within the range A-M. Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named Production worker that inherits from the Employee class. The Production worker class should have fields to hold the following information: Shift (an integer) Hourly pay rate (a double) The workday is divided into two shifts: day and night. The shift field will be an integer value representing the shift that the employee works. The day shift is shift 1 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 Production worker object.

Explanation / Answer

Please find my implementation.

######### Employee.java ###############

public class Employee

{

   private String Empname;

   private String Empnumber;

   private String Hiredate;

   public Employee()

   {

       Empname="";

       Empnumber="";

       Hiredate="";

   }

   public Employee (String Empname, String Empnumber,String Hiredate)

   {

       setName(Empname);

       setNumber(Empnumber);

       setHiredate(Hiredate);

   }

   public void setName(String n)

   {

       if( n == null || n.trim().equals(""))

           return;

       Empname = n;

   }

   public void setNumber(String num)

   {

       Empnumber = num;

   }

   public void setHireDate(String h)

   {

       Hiredate = h;

   }

   public String getName()

   {

       return Empname;

   }

   public String getNumber()

   {

       return Empnumber;

   }

   public String getHireDate()

   {

       return Hiredate;

   }

   private void setHiredate(String Hiredate) {

       this.Hiredate = Hiredate;

   }

}

############# ProductionWorker.java ##############

public class ProductionWorker extends Employee

{

   private int shift; // The employee's shift

   private double hourpayrate; // The employee's pay rate

   public ProductionWorker(String Empname, String Empnumber, String Hiredate,int shift, double hourpayrate)

   {

       super(Empname, Empnumber, Hiredate);

       setShift(shift);

       setHourlyPayRate(hourpayrate);

   }

   public int getShift()

   {

       return shift;

   }

   public double getHourlyPayRate()

   {

       return hourpayrate;

   }

   public void setShift(int s)

   {

       if(s < 0){

           return;

       }

       shift = s;

   }

   /**

   The setPayRate method sets the employee's pay rate.

   @param p The employee's pay rate.

   */

   public void setHourlyPayRate(double r)

   {

       if(r < 0)

           return;

       hourpayrate = r;

   }

}

############   ProductionWorkerDemo.java #############

import java.util.Scanner;

public class ProductionWorkerDemo

{

   public static void main(String[] args)

   {

       String name,id,date;

       int shift;

       double pay;

       // Creates Scanner object

       Scanner keyboard = new Scanner(System.in);

       // Gets the user's name.

       System.out.println("Enter employee name: ");

       name = keyboard.nextLine();

       // Gets the user's employee number.

       System.out.println("Enter employee ID: ");

       id = keyboard.nextLine();

       // Gets the user's hire date.

       System.out.println("Enter employee date ");

       date = keyboard.nextLine();

       System.out.println("1-day Shift/n2-Night shift");

       System.out.println("Enter employee shift: ");

       shift = keyboard.nextInt();

       System.out.println("Enter hourly pay");

       pay = keyboard.nextDouble();

       // Creates an Production worker object.

       ProductionWorker pw = new ProductionWorker(name,id,date,shift,pay);

       System.out.println();

       System.out.println("Employee Name: " + pw.getName());

       System.out.println("Employee ID: " + pw.getNumber());

       System.out.println("Hire Date: " + pw.getHireDate());

       System.out.println("Shift: " + pw.getShift());

       System.out.println("Hourly Rate: " + pw.getHourlyPayRate());

       keyboard.close();

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote