Question: Exception Project Modify the Employee and ProductionWorker classes from Programming Challenge 1 of Chapter 10 so that they throw exceptions when the following errors occur:

Exception Project

Modify the Employee and ProductionWorker classes from Programming Challenge 1 of Chapter 10 so that they throw exceptions when the following errors occur:

The Employee class should throw an exception named InvalidEmployeeNumber when it receives an invalid employee number.

The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift.

The ProductionWorker class should throw an exception named InvalidPayRate when it receives a negative number for the hourly pay rate.

Write the InvalidEmployeeNumber, InvalidShift, and InvalidPayRate exception classes. Write a test program that demonstrates how each exception condition works. (java)

Employee.java

public class employee { private String name; private String date; private String empnumber; public employee() { name = " "; date = " "; empnumber = " "; } public employee(String name, String date, String empnumber) { this.name = name; this.date = date; this.empnumber = empnumber; } public String getName() { return name; } public String getDate() { return date; } public String getNumber() { return empnumber; } public String toString() { return "Name: " + name + " Employee Number: " + empnumber + " Hire Date: " + date; } }

productionworker.java

public class productionworker extends employee { public static final int DAYSHIFT = 1; public static final int NIGHTSHIFT = 2; private int shift; private double payrate; public productionworker() { super(); shift = DAYSHIFT; payrate = 0.0; } public productionworker(String n, String d, String e, int shift, double payrate) { super(n,d,e); this.shift = shift; this.payrate = payrate; } public int getShift() { return shift; } public double payrate() { return payrate; } public String toString() { String str = super.toString(); if(shift == DAYSHIFT) { str += "day shift"; } else if(shift == NIGHTSHIFT) { str += "night shift"; } return str += "hourly payrate:" + 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!