Question: Java - Use the provided Payroll class . The instructions for this are: Write 4 exception classes for the following 4 error conditions: An empty

Java - Use the provided Payroll class.

The instructions for this are:

Write 4 exception classes for the following 4 error conditions:

An empty string is given for the employees name. An invalid value is given for the employees identification number. If you implemented this field as a string, then an empty string would 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. Hours worked may have a decimal fraction. An invalid number is given for the hourly pay rate. This would be a negative number or a number greater than 25. Pay rate may have a decimal fraction. Modify the Payroll class provided so that it throws the appropriate exceptions when any one of these 4 exceptions occurs. You should note that each different exception requires a separate class. Also, note that you need to add a throws clause to the heading line of each method that may throw a specific exception. Demonstrate the exception classes in a demo program. You will need separate try-catch blocks for each exception that you are handling.

Payroll class

/** The Payroll class stores data about an employee's pay for the Payroll Class programming challenge. */

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; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!