Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given attached you will find a file from Programming Challenge 5 of chapter 6 with required you to write a Payroll class that calculates an

Given attached you will find a file from Programming Challenge 5 of chapter 6 with 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 to the employees ID number. If you implemented this field as a string, then an empty string could 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.

1.Write a program in Java using JOptionPane

2. Modify the Payroll class so that it throws the appropriate exception when any of these errors occur. Demonstrate the exception classes in a program.

3. Make sure the program should run both internally and externally.

/** Payroll class Chapter 6, Programming Challenge 5 */ 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

Students also viewed these Databases questions