Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an EmployeeException class whose constructor receives a String that consi

ID: 3535281 • Letter: C

Question

Create an EmployeeException class whose constructor receives a String that consists of an employee’s ID and pay rate. Create an Employee class with two fields, idNum and hourlyWage. The Employee constructor requires values for both fields. Upon construction, throw an EmployeeException if the hourlyWage is less than $6.00 or over $50.00. Write a program that establishes at least three Employees with hourlyWages that are above, below, and within the allowed range. Save the program as ThrowEmployee.java.

Explanation / Answer


public class Employee {
private int id;
private double hourlyWage;
public Employee(int id, double hourlyWage) {
super();
this.id = id;
this.hourlyWage = hourlyWage;
if(hourlyWage < 6.00 || hourlyWage > 50) {
try {
throw new EmployeeException("Emp Id: " + id + "payRate: " + hourlyWage);
}
catch(EmployeeException e) {
System.out.println("Error :" + e.getMsg());
}
}
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getHourlyWage() {
return hourlyWage;
}
public void setHourlyWage(double hourlyWage) {
this.hourlyWage = hourlyWage;
}

}

public class EmployeeException extends Exception {
private String msg;
public EmployeeException(String msg) {
this.msg =msg;
}
public String getMsg() {
return msg;
}

}

public class ThrowEmployee {

/**
* @param args
*/
public static void main(String[] args) {
Employee e1 = new Employee(123, 3);
Employee e2 = new Employee(123, 8);
Employee e3 = new Employee(123, 56);

}

}
output:

Error :Emp Id: 123payRate: 3.0
Error :Emp Id: 123payRate: 56.0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote