Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database And Expert Systems Applications 31st International Conference Dexa 2020 Bratislava Slovakia September 14 17 2020 Proceedings Part 1 Lncs 12391

Authors: Sven Hartmann ,Josef Kung ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

303059002X, 978-3030590024

More Books

Students also viewed these Databases questions

Question

what is the difference between GPU and CPU?

Answered: 1 week ago