Question: Java code, not C++. Payroll class Exceptions Programming Challenge 5 of Chapter 6 required you to write a Payroll class that calculates an employees payroll.
Java code, not C++.
Payroll class Exceptions Programming Challenge 5 of Chapter 6 required you to write a Payroll class that calculates an employees payroll.
Write exception classes for the following error conditions:
An empty string is given for the employees name.
An invalid value is given for the employees ID 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.
An invalid number is given for the hourly pay rate. This would be a negative number or a number greater than 25.
Modify the Payroll class so that it throws the appropriate exception when any of these errors occurs. Demonstrate the exception classes in a program.
File name must be: PayRollExceptions.java
Test Case1:
Enter the employee's name: John
Enter employee number, (ex. 999-M): 9999
Enter the employee's hourly rate: 20
Enter the number of hours the employee has worked: 20
Error: Numericals in ID must be between 0-9 and letters must be between A-M
Test Case2:
Enter the employee's name: John
Enter employee number, (ex. 999-M): 999-N
Enter the employee's hourly rate: 20
Enter the number of hours the employee has worked: -2
Error: Numericals in ID must be between 0-9 and letters must be between A-M
Test Case3:
Enter the employee's name: John
Enter employee number, (ex. 999-M): 999-J
Enter the employee's hourly rate: 20
Enter the number of hours the employee has worked: -2
Error: Hours Cannot be negative or greater than 84
Test Case4:
Enter the employee's name: John
Enter employee number, (ex. 999-M): 999-H
Enter the employee's hourly rate: -2
Enter the number of hours the employee has worked: 20
Error: Hourly Rate Cannot be negative or greater than 25
Test Case5:
Enter the employee's name: John
Enter employee number, (ex. 999-M): 999-H
Enter the employee's hourly rate: 20
Enter the number of hours the employee has worked: 40
Employees name: John
ID: 999-H
Hourly Rate: $20.0
Hours: 40 hrs
Gross Pay: $800.0
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
