Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genetic Databases

Authors: Martin J. Bishop

1st Edition

0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

Ask how you may be of assistance.

Answered: 1 week ago