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

Given attached you will find a file from Programming Challenge 5 of chapter 6 wi

ID: 3735892 • Letter: G

Question

Given attached you will find a file from Programming Challenge 5 of chapter 6 with required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions:

An empty string is given for the employee’s name.

An invalid value is given to the employee’s ID number. If you implemented this field as a string, then an empty string could be invalid. If you implemented this field as a numeric variable, then a negative number or zero would be invalid.

An invalid number is given for the number of hours worked. This would be a negative number or a number greater than 84.

An invalid number is given for the hourly pay rate. This would be a negative number or a number greater than 25.

1.Write a program in Java using JOptionPane

2. Modify the Payroll class so that it throws the appropriate exception when any of these errors occur. Demonstrate the exception classes in a program.

3. Make sure the program should run both internally and externally.

/**
   Payroll class
   Chapter 6, Programming Challenge 5
*/

public class Payroll
{
   private String name; // Employee name
   private int idNumber; // ID number
   private double payRate; // Hourly pay rate
   private double hoursWorked; // Number of hours worked

   /**
The constructor initializes an object with the
employee's name and ID number.
@param n The employee's name.
@param i The employee's ID number.
   */

   public Payroll(String n, int i)
   {
name = n;
idNumber = i;
   }

   /**
The setName sets the employee's name.
@param n The employee's name.
   */

   public void setName(String n)
   {
name = n;
   }

   /**
The setIdNumber sets the employee's ID number.
@param i The employee's ID number.
   */
  
   public void setIdNumber(int i)
   {
idNumber = i;
   }

   /**
The setPayRate sets the employee's pay rate.
@param p The employee's pay rate.
   */
  
   public void setPayRate(double p)
   {
payRate = p;
   }

   /**
The setHoursWorked sets the number of hours worked.
@param h The number of hours worked.
   */

   public void setHoursWorked(double h)
   {
hoursWorked = h;
   }

   /**
The getName returns the employee's name.
@return The employee's name.
   */

   public String getName()
   {
return name;
   }

   /**
The getIdNumber returns the employee's ID number.
@return The employee's ID number.
   */
  
   public int getIdNumber()
   {
return idNumber;
   }

   /**
The getPayRate returns the employee's pay rate.
@return The employee's pay rate.
   */

   public double getPayRate()
   {
return payRate;
   }

   /**
The getHoursWorked returns the hours worked by the
employee.
@return The hours worked.
   */


   public double getHoursWorked()
   {
return hoursWorked;
   }

   /**
The getGrossPay returns the employee's gross pay.
@return The employee's gross pay.
   */

   public double getGrossPay()
   {
return hoursWorked * payRate;
   }
}

Explanation / Answer

here is your files : -------->>>>>>>

StringException.java : -------->>>>>>

public class StringException extends Exception{
public StringException(String msg){
  super(msg);
}
}

NumberException: -------------->>>>>>>>>>>

public class NumberException extends Exception{
public NumberException(String msg){
  super(msg);
}
}

Payroll.java : -------->>>>>>>>>

public class Payroll
{
private String name;// Employee name
private int idNumber;// ID number
private double payRate; // Hourly pay rate
private double hoursWorked; // Number of hours worked
/**
The constructor initializes an object with the
employee's name and ID number.
@param n The employee's name.
@param i The employee's ID number.
*/
public Payroll(String n, int i)throws StringException,NumberException{
  setName(n);
  setIdNumber(i);
}
/**
The setName sets the employee's name.
@param n The employee's name.
*/

public void setName(String n)throws StringException{
  if(n.equals("")){
   throw new StringException("Not A valid Name");
  }
  name = n;
}

/**
The setIdNumber sets the employee's ID number.
@param i The employee's ID number.
*/

public void setIdNumber(int i)throws NumberException{
  if(i <= 0){
   throw new NumberException("The Value For ID is either Negative or Zero");
  }
  idNumber = i;
}

/**
The setPayRate sets the employee's pay rate.
@param p The employee's pay rate.
*/

public void setPayRate(double p)throws NumberException{
  if(p < 0 || p > 25){
   throw new NumberException("The value for PayRate is either Negative or larger than 25");
  }
  payRate = p;
}

/**
The setHoursWorked sets the number of hours worked.
@param h The number of hours worked.
*/

public void setHoursWorked(double h)throws NumberException{
  if(h < 0 || h > 84){
   throw new NumberException("The value for Hours Worked is either Negative or larger than 84");
  }
  hoursWorked = h;
}

/**
The getName returns the employee's name.
@return The employee's name.
*/

public String getName(){
  return name;
}

/**
The getIdNumber returns the employee's ID number.
@return The employee's ID number.
*/

public int getIdNumber(){
  return idNumber;
}

/**
The getPayRate returns the employee's pay rate.
@return The employee's pay rate.
*/

public double getPayRate(){
  return payRate;
}

/**
The getHoursWorked returns the hours worked by the
employee.
@return The hours worked.
*/

public double getHoursWorked(){
  return hoursWorked;
}

/**
The getGrossPay returns the employee's gross pay.
@return The employee's gross pay.
*/

public double getGrossPay(){
  return hoursWorked * payRate;
}
}

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