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

please help when compling the code I keep getting the error production worker cl

ID: 3804162 • Letter: P

Question

please help when compling the code I keep getting the error production worker class is duplicated. help me to solve this

class ProductionWorker extends Employee
   {
       private int shift;
       private double hourlyRate;
       private int hours;
       //constructors to set name,number and hiredate, shift,hourly rate and hours
       public ProductionWorker(String ename,String enumber,String hd,int sh,double hrate,int hr)
           {
               super(ename,hd,enumber);
               shift=sh;
               hourlyRate=hrate;
               hours=hr;
           }

       //accessors methods of ProductionWorker class defined below
       public int getHours()
           {
           return hours;
           }
       public int getShift()
           {
           return shift;
           }
       public double getHourlyRate()
           {
           return hourlyRate;
           }
       //mutator methods of ProductionWorker class defined below
       public void setShift(int sh)
           {
           shift=sh;
           }
       public void setHourlyRate(double hr)
           {
           hourlyRate=hr;
           }
       public void setHours(int hr)
           {
           hours=hr;
           }
       public String getName()
           {
           return super.getName();
           }
       public String getHireDate()
           {
           return super.getHireDate();
           }
       public String getNumber()
               {
               return super.getNumber();
           }
       //calculate the pay
       public double calculatePay()
                   {
                   double pay=hours*hourlyRate;
                   return pay;
           }
       }

Explanation / Answer

/*
* The employee class that represents the
* object of employee.
* */
//Employee.java
public class Employee
{
   //private data members
   private String ename;
   private String hd;
   private String enumber;
   //Constructor that takes ename, hd and enumber
   public Employee(String ename, String hd, String enumber)
   {
       //set fields
       this.ename=ename;
       this.hd=hd;
       this.enumber=enumber;
   }
  
   //Regurns name
   public String getName()
   {
       return ename;
   }
  
   //Regurns hire date
   public String getHireDate()
   {
       return hd;
   }
  
   //Regurns enumber
   public String getNumber()
   {
       return enumber;
   }
}//end of class employee

------------------------------------------------


//ProductionWorker.java
//The class ProductionWorker inherited properties
//fraom Employee
class ProductionWorker extends Employee
{
   private int shift;
   private double hourlyRate;
   private int hours;
   //constructors to set name,number and hiredate, shift,hourly rate and hours
   public ProductionWorker(String ename,String enumber,String hd,
           int sh,double hrate,int hr)
   {
       //callig Employee class constructor
       super(ename,hd,enumber);
       shift=sh;
       hourlyRate=hrate;
       hours=hr;
   }

   //accessors methods of ProductionWorker class defined below
   public int getHours()
   {
       return hours;
   }
   public int getShift()
   {
       return shift;
   }
   public double getHourlyRate()
   {
       return hourlyRate;
   }
   //mutator methods of ProductionWorker class defined below
   public void setShift(int sh)
   {
       shift=sh;
   }
   public void setHourlyRate(double hr)
   {
       hourlyRate=hr;
   }
   public void setHours(int hr)
   {
       hours=hr;
   }
   public String getName()
   {
       return super.getName();
   }
   public String getHireDate()
   {
       return super.getHireDate();
   }
   public String getNumber()
   {
       return super.getNumber();
   }
   //calculate the pay
   public double calculatePay()
   {
       double pay=hours*hourlyRate;
       return pay;
   }
}

------------------------------------------------


/**
* The java class TestProductionWorker that tests
* the class ProductionWorker. Print details to
* console.
* */
//TestProductionWorker.java
public class TestProductionWorker
{
   public static void main(String[] args)
   {
      
       //Create an instance of        ProductionWorker
       ProductionWorker pworker=
               new ProductionWorker("Johnson", "PW101", "12/02/2012", 1, 3.5, 40);
      
       //print details of the pworker object
       System.out.println("Product worker details");
       System.out.println("Name : "+pworker.getName());
       System.out.println("Number : "+pworker.getNumber());
       System.out.println("HireDate : "+pworker.getHireDate());
       System.out.println("Shift : "+pworker.getShift());
       System.out.println("Rate : $"+pworker.getHourlyRate());
       System.out.println("Hours : "+pworker.getHours());
       System.out.println("Total Pay : $"+pworker.calculatePay());
      
   }
}

------------------------------------------------

Sample Output:

Product worker details
Name : Johnson
Number : PW101
HireDate : 12/02/2012
Shift : 1
Rate : $3.5
Hours : 40
Total Pay : $140.0