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

can i please get help with this problem im so confused TeamLeader Class In a par

ID: 3690129 • Letter: C

Question

can i please get help with this problem

im so confused

TeamLeader Class

In a particular factory, a team leader is an hourly paid production worker that leads

a small team. In addition to hourly pay, team leaders earn a fixed monthly bonus.

Team leaders are required to attend a minimum number of hours of training per year.

Design a TeamLeader class that extends the ProductionWorker class you designed in

Programming Challenge 1.

The TeamLeader class should have fields for the monthly bonus amount, the required

number of training hours, and the number of training hours that the team leader has

Attended.

Write one or more constructors and the appropriate accessor and mutator methods for

The class.

If you have done the practice problems, test the program to make sure these parts works. If not, you can find the other’s solution in Unit 7 discussion board.

Add the TeamLeader class (Programming Challenge 3 on P698-699) to the program. The class includes:

A data members

Two constructors, one is default, another one is with parameters (to initialize data members in super classes and its own class)

Mutators and accessors for all data members.

Add the toString() method in all of the three classes.

Create your own exception classes:

·        An exception class, InvalidEmployeeNumber, used in the Employee class

·        An exception class, InvalidShift, used in the ProductionWorker class

·        An exception class, InvalidPayRate, used in the ProductionWorker class

·        An exception class, InvalidReqTrainingHours, used in the TeamLeader class

Modify the service classes so they throw (not handle) exceptions in methods when the following errors occur:

·        The Employee class should throw the InvalidEmployeeNumber when it receives an employee number that is not in the format XXX-L (each X is a digit within the range 0-9 and L is a letter within the range A-M).

·        The ProductWorker class should throw the InvalidShift when it receives an invalid shift.

·        The ProductWorker class should throw the InvalidPayRate when it receives a negative number for hourly pay rate.

·        The TeamLeader class should throw the InvalidReqTrainingHours when it receives a value that is less than 20 for the required number of training hours.

Notes:

One exception may be thrown in more than one method, e.g., in mutator and constructor

One method may throw multiple exceptions including these for its own class and for its super class. If the called method throws exception(s), the calling methods need to throw the exception(s).

Handle exceptions in the application class.

An incomplete application class is provided. To handle exceptions and test all exceptions in one application at the same time, complete the application class by defining two methods, createWorker() and createTeamLeader().

The main() method is completed (don’t modify). It just calls two methods createWorker() and createTeamLeader() multiple times to test valid and invalid data.

Both methods have parameters. Inside each method, use the parameters as arguments in the constructor to instantiate an object (ProductionWorker in createWorker() and TeamLeader in createTeamLeader()), and handle your own exceptions.

To handle multiple exceptions, please use only ONE try block followed by MULTIPLE catch blocks.

Feel free to handle other exceptions.

Test your program. The screen shot is provided.

Here is the incomplete application class:

Invalid arguments in method calls are in RED. (You can test more invalid cases, such as 123, 12A-A, 123-AA, and so on, to make sure your validation is correct.)

DAY_SHIFT and NIGHT_SHIFT are public, static, and final int in the service class.

public class EmpDemo
{
   public static void main(String[] args)
   {
      // Create a ProductionWorker object with valid data.
      System.out.println(" Creating a ProductionWorker object with valid data.");
      createWorker("John Smith", "123-A", "11-15-2009",
                   ProductionWorker.DAY_SHIFT, 16.50);
     
      // Try to use an invalid employee number.
      System.out.println(" Attempting an invalid employee number...");
      createWorker("Bill Dowman", "10001", "11-15-2010",
                   ProductionWorker.DAY_SHIFT, 16.50);
  
      // Try to use an invalid shift number.
      System.out.println(" Attempting an invalid shift number...");
      createWorker("Mary Johnson", "456-B", "11-15-2011",
                  66, 16.50);
  
    // Try to use a negative pay rate.
      System.out.println(" Attempting a negative pay rate...");
      createWorker("James Sears", "789-C", "11-15-2012",
                   ProductionWorker.NIGHT_SHIFT, -99.00);
                  
      //Create a TeamLeader object with valid data.
      System.out.println(" Create a TeamLeader object with valid data.");
     
      createTeamLeader("John Doe", "777-D", "11-15-2013",
                   ProductionWorker.DAY_SHIFT, 99.00, 120.00, 20, 12);
                   
      // Try to use an invalid number of the training hour         
      System.out.println(" Attempting an invalid number of hours...");
      createTeamLeader("Steven Chang", "888-E", "11-15-2014",
                   ProductionWorker.DAY_SHIFT, 99.00, 120.00, 15, 13);
  
   }

   //Create the createWorker() method here!

   //Create the createTeamLeader() method here!

This the Employee and ProductionWorker Class

import java.io.*;
import java.util.Scanner;

class Employee
{
   //Fields
   private String n;      //Employee's name
   private String en;    //Employee's number
   private String d; //Date employee was hired
  
  
      /**
   No-arg constructor
   */
   public Employee()
   {
      n = "";
      en = "";
     d = "";
   }
      /**
   Constructor
   @param n Employee's name
   @param en Employee's number
   @param d Date employee was hired
   */
   public Employee(String n, String en, String d)
{
      setName (n);
      setNumber (en);
      setHireDate (d);
   }
  

      //Mutator Functions
      //sets employee name
   public void setName (String name)
   {
      n=name;
   }
  
      //sets employee number
   public void setNumber (String num)
   {
      en= num;     
   }
  
      //set hire date
   public void setHireDate (String hire)
   {
      d=hire;
   }
  
      /* Accessor functions */
      //returns employee name
   public String getName ()
   {
      return n;
   }
  
   public String getNumber ()
   {
      return en;
   }
  
      //returns hire date
   public String getHireDate()        
   {
      return d ;
   }
}


class ProductionWorker extends Employee

{
   //fields
   private int shift;
   private double hourpayrate;
  
  
   //constructors
   public ProductionWorker (String n, String en, String d, int shift, double hourpayrate)
   {
      super (n,en,d);
      setShift (shift);
      setHourlyPayRate (hourpayrate);
   }
  
  
   //Accessor
   public int getShift ()
   {
      return shift;
   }
  
   public double getHourlyPayRate ()
   {
      return hourpayrate;
   }
  
   //mutator
   public void setShift (int s)
   {
      shift = s;
   }
  
   public void setHourlyPayRate (double r)
   {
      hourpayrate = r;
   }
  
}



public class employeeDemo
{

   public static void main (String [] args)
   {
      String name, id , date;
      double pay;
      int shift;
     
     
      //create Scanner object
      Scanner keyboard = new Scanner (System.in);
     
      //inputing date
      System.out.println ("Enter employee name :");
      name = keyboard.nextLine ();
    
      //inputing id
      System.out.println ("Enter employee id:");
      id = keyboard.nextLine ();
     
     
       //inputing id
      System.out.println ("Enter employee date:");
      date = keyboard.nextLine ();
     
        //inputing id
      System.out.println ("1-Day Shift 2-Nigth shift");
      System.out.println ("Enter employee shift:");
      shift = keyboard.nextInt ();
     
        //inputing id
      System.out.println ("Enter employee hourly pay:");
      pay = keyboard.nextDouble ();
     
     
      //instantiatin worker
      ProductionWorker pw = new ProductionWorker (name, id, date, shift, pay);
     
     
   //outputting
   System.out.println ("Employee Name: " + pw.getName());
   System.out.println ("Employee ID: " + pw.getNumber());
System.out.println ("Employee Hire Date: " + pw.getHireDate());
   System.out.println ("Employee Shift: " + pw.getShift());
   System.out.println ("Employee HOurly Rate: " + pw.getHourlyPayRate ());
  
   }//end main
  
   }
      
                  
                       
  

Explanation / Answer

import java.io.*;
import java.util.Scanner;
import java.util.regex.*;

class Employee
{
   //Fields
   private String n;      //Employee's name
   private String en;    //Employee's number
   private String d; //Date employee was hired


      /**
   No-arg constructor
   */
   public Employee()
   {
      n = "";
      en = "";
     d = "";
   }
      /**
   Constructor
   @param n Employee's name
   @param en Employee's number
   @param d Date employee was hired
   */
   public Employee(String n, String en, String d)
{
      try
      {
      setName (n);
      setNumber (en);
      setHireDate (d);
      }
      catch(InvalidEmployeeNumber e)
      {
          System.out.println(e.getMessage());
      }
   }


      //Mutator Functions
      //sets employee name
   public void setName (String name)
   {
      n=name;
   }

      //sets employee number
   public void setNumber (String num) throws InvalidEmployeeNumber
   {
       if(!Pattern.matches("[0-9]{3}-[A-M]",num))
       throw new InvalidEmployeeNumber("Invalid employee no provided");
      en= num;   
   }

      //set hire date
   public void setHireDate (String hire)
   {
      d=hire;
   }

      /* Accessor functions */
      //returns employee name
   public String getName ()
   {
      return n;
   }

   public String getNumber ()
   {
      return en;
   }

      //returns hire date
   public String getHireDate()      
   {
      return d ;
   }
   public String toString()
    {
           //outputting
           String output="";
   output="Employee Name: " + getName();
   output+="Employee ID: " + getNumber();
   return output;
    }
}


class ProductionWorker extends Employee

{
   //fields
   private int shift;
   private double hourpayrate;
   static int DAY_SHIFT=1;
   static int NIGHT_SHIFT=2;

   //constructors
   public ProductionWorker (String n, String en, String d, int shift, double hourpayrate)
   {
      super (n,en,d);
      try
      {
      setShift (shift);
      setHourlyPayRate (hourpayrate);
      }
      catch(InvalidShift e)
      {
          System.out.println(e.getMessage());
      }
      catch(InvalidPayRate e)
      {
          System.out.println(e.getMessage());
      }
   }


   //Accessor
   public int getShift ()
   {
      return shift;
   }

   public double getHourlyPayRate ()
   {
      return hourpayrate;
   }

   //mutator
   public void setShift (int s) throws InvalidShift
   {
       if(s!=1 && s!=2)
       throw new InvalidShift ("Invalid shift value provided");
      shift = s;
   }

   public void setHourlyPayRate (double r) throws InvalidPayRate
   {
       if(r<0)
       throw new InvalidPayRate("Pay rate can't be negatice");
      hourpayrate = r;
   }
   public String toString()
    {
           //outputting
           String output="";
   output="Employee Name: " + getName();
   output+="Employee ID: " + getNumber();
output +="Employee Hire Date: " + getHireDate();
   output +="Employee Shift: " + getShift();
   return output;
    }

}

class TeamLeader extends ProductionWorker
{
    double bonus,reqHours,attendHours;

     public TeamLeader (String n, String en, String d, int shift, double hourpayrate,double b,double rh,double ah)
   {
      super (n,en,d,shift,hourpayrate);
       try
       {
      setBonus (b);
      setRequiredHours (rh);
      setAttendedHours(ah);
       }
       catch(InvalidReqTrainingHours e)
       {
           System.out.println(e.getMessage());
       }
   }
  
    public void setBonus(double b)
    {
        bonus=b;
    }
    public double getBonus()
    {
        return bonus;
    }
    public double getRequiredHours()
    {
        return reqHours;
    }
    public double getAttendedHours()
    {
        return attendHours;
    }
    public void setRequiredHours(double rh) throws InvalidReqTrainingHours
    {
        if(rh<20 )
        throw new InvalidReqTrainingHours("Required training hours should be greater than 1");
        reqHours=rh;
    }
    public void setAttendedHours(double ah)
    {
        attendHours=ah;
    }
    public String toString()
    {
           //outputting
           String output="";
   output="Employee Name: " + getName();
   output+="Employee ID: " + getNumber();
output +="Employee Hire Date: " + getHireDate();
   output +="Employee Shift: " + getShift();
   output +="Employee Bonus: " + getBonus ();
   output +="Employee Required Hours: " + getRequiredHours ();
   output +="Employee Attended Hours: " + getAttendedHours ();
   return output;
    }
}

class InvalidReqTrainingHours extends Exception
{
    InvalidReqTrainingHours(String e)
    {
        super(e);
    }
}

class InvalidShift extends Exception
{
    InvalidShift (String e)
    {
        super(e);
    }
}
class InvalidPayRate extends Exception
{
    InvalidPayRate (String e)
    {
        super(e);
    }
}
class InvalidEmployeeNumber   extends Exception
{
    InvalidEmployeeNumber (String e)
    {
        super(e);
    }
}
public class EmpDemo
{

   public static void main(String[] args)
   {
      // Create a ProductionWorker object with valid data.
      System.out.println(" Creating a ProductionWorker object with valid data.");
      createWorker("John Smith", "123-A", "11-15-2009",ProductionWorker.DAY_SHIFT, 16.50);
   
      // Try to use an invalid employee number.
      System.out.println(" Attempting an invalid employee number...");
     createWorker("Bill Dowman", "10011", "11-15-2010",ProductionWorker.DAY_SHIFT, 16.50);

      // Try to use an invalid shift number.
      System.out.println(" Attempting an invalid shift number...");
      createWorker("Mary Johnson", "456-B", "11-15-2011",66, 16.50);

    // Try to use a negative pay rate.
      System.out.println(" Attempting a negative pay rate...");
     createWorker("James Sears", "789-C", "11-15-2012",ProductionWorker.NIGHT_SHIFT, -99.00);
                
      //Create a TeamLeader object with valid data.
      System.out.println(" Create a TeamLeader object with valid data.");
      createTeamLeader("John Doe", "777-D", "11-15-2013",ProductionWorker.DAY_SHIFT, 99.00, 120.00, 20, 12);
                 
      // Try to use an invalid number of the training hour       
      System.out.println(" Attempting an invalid number of hours...");
      createTeamLeader("Steven Chang", "888-E", "11-15-2014",ProductionWorker.DAY_SHIFT, 99.00, 120.00, 15, 13);
     }
     public static void createWorker(String n, String en, String d, int shift, double hourpayrate)
   {
       new ProductionWorker(n,en,d,shift,hourpayrate);
   }
   public static void createTeamLeader(String n, String en, String d, int shift, double hourpayrate,double b,double rh,double ah)
   {
       new TeamLeader (n,en,d,shift, hourpayrate, b, rh, ah);
   }
}
     

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote