Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chapter 10 Starting Out With Java Early Objects 6E 5. Payroll Class Exceptions Programming Challenge 5 of Chapter 3 required you to write a Payroll

Chapter 10 Starting Out With Java Early Objects 6E

5. Payroll Class Exceptions Programming Challenge 5 of Chapter 3 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 it throws the appropriate exception when any of these errors occurs. Demonstrate the exception classes in a program.

Below is program Challenge 5 of Chapter 3

image text in transcribed

6. Payroll Class Design a Payroll class that has fields for an employee's name, ID number, hourly pay rate, and number of hours worked. Write the appropriate accessor and mutator methods and a constructor that accepts the employee's name and ID number as arguments. The class should also have a method that returns the employee's gross pay, which is calculated as the number of hours worked multiplied by the hourly pay rate. Write a program that demon- strates the class by creating a Payroll object, then asking the user to enter the data for an employee. The program should display the amount of gross pay earned 6. Payroll Class Design a Payroll class that has fields for an employee's name, ID number, hourly pay rate, and number of hours worked. Write the appropriate accessor and mutator methods and a constructor that accepts the employee's name and ID number as arguments. The class should also have a method that returns the employee's gross pay, which is calculated as the number of hours worked multiplied by the hourly pay rate. Write a program that demon- strates the class by creating a Payroll object, then asking the user to enter the data for an employee. The program should display the amount of gross pay earned

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

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago