Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
Create an employee class code titled Employee.java for the UML diagram below. Also, create and submit a test driver program titled EmployeeExceptionHandling.java as described below.
Create an employee class code titled Employee.java for the UML diagram below. Also, create and submit a test driver program titled EmployeeExceptionHandling.java as described below. Create the following custom exception classes that extends Exception and invoke the superclasss constructors no arg & with arg with a message InvalidHourlyPayException.java can be thrown if the employee pay rate is below MINHOURLYPAY or above MAXHOURLYPAY InvalidHoursException.java that can be thrown if the number of hours employee worked is below MINHOURS or above MAXHOURS Download and use the following text files to test your program empFiletxtDownload empFiletxt empFiletxtDownload empFiletxt empFiletxtDownload empFiletxt empFiletxtDownload empFiletxt empFiletxtDownload empFiletxt Submission Instruction Submit Employee.java file Submit InvalidHourlyPayException.java file. Submit InvalidHoursException.java file. Submit EmployeeExceptionHandling.java file. Problem Statement: Let's enhance Lab so that it includes reading input from a file & throwing exceptions. The program will read from text files above that you can download and displays the output as shown below. The program should throw FileNotFoundException exception if files is not in the current directory. In addition, the two custom exception classes InvalidHourlyPayException & InvalidHoursException should be created. See example in Section Defining Custom Exception Classes. These exceptions should be thrown by the methods in the Employee class as shown on the UML diagram below and handled in the main class. The program should continue processing the data on the files only after verifying that the file exists, is not a directory, and can be read or exit if otherwise. Check methods in the File class such as exists isDirectory canRead The program must close files that are opened. Employee class Employee MINHOURS: double REGULARHOURS: double MAXHOURS: double MINHOURLYPAY: double MAXHOURLYPAY: double OVERTIMEPAY: double name: String employeeId: int shift: Boolean hourlyPay: double hoursWorked: double Employee Employeen: String, i:int, s:Boolean, p:double, h : doublethrows InvalidHourlyPayException, InvalidHoursException setNamen: String setemployeeIDi:int setShifts:Boolean setHourlyPayp:double throws InvalidHourlyPayException setHoursWorkedp:double throws InvalidHoursException getname : String getemployeeID : int getShift : Boolean getHoursWorked : double getHourlyPay : double calculateOvertimePay h : double : double throws InvalidHoursException calculateRegPayh : double: double throws InvalidHoursException printPayStub h : double throws InvalidHoursException Your program should do the following : Start create array with the list of input files Example String myFileList empFiletxt "empFiletxt"empFiletxt "empFiletxt "empFiletxt; Loop until each file in the array is run instantiate a File object verify file exists, is not a directory, or is readable instantiate an Employee object instantiate a scanner object Note: Inputs that generate exception, as highlighted in the UML, must be within a try and catch block individually or together Loop until there is no more employee record in the file read and set employee name read and set employee ID read and set employee shift input "day" true input "night" false read and set employee's hourly pay read and set employee hourly pay read and set hours the employee worked display employee pay stub as shown in the example End Loop close opened files End Loop end The program run should display the output shown below: Employee Name: Ann Employee ID: Pay Period: Friday Regular Pay: $ Overtime Pay: $ Gross Pay: $ Employee Name: Bob Employee ID: Pay Period: Saturday Regular Pay: $ Overtime Pay: $ Gross Pay: $ Employee Name: Cara Employee ID: Pay Period: Friday Regular Pay: $ Overtime Pay: $ Gross Pay: $ Employee Name: Don Employee ID: Pay Period: Saturday Regular Pay: $ Overtime Pay: $ Gross Pay: $ InvalidHourlyPayException: Invalid hourly pay rate: InvalidHourlyPayException: Invalid hourly pay rate: InvalidHoursException: Invalid number of hours: InvalidHoursException: Invalid number of hours: Thank you for using the total pay Calculator! Good Bye!
Create an employee class code titled Employee.java for the UML diagram below. Also, create and submit a test driver program titled EmployeeExceptionHandling.java as described below.
Create the following custom exception classes that extends Exception and invoke the superclasss constructors no arg & with arg with a message
InvalidHourlyPayException.java can be thrown if the employee pay rate is below MINHOURLYPAY or above MAXHOURLYPAY
InvalidHoursException.java that can be thrown if the number of hours employee worked is below MINHOURS or above MAXHOURS
Download and use the following text files to test your program
empFiletxtDownload empFiletxt
empFiletxtDownload empFiletxt
empFiletxtDownload empFiletxt
empFiletxtDownload empFiletxt
empFiletxtDownload empFiletxt
Submission Instruction
Submit Employee.java file
Submit InvalidHourlyPayException.java file.
Submit InvalidHoursException.java file.
Submit EmployeeExceptionHandling.java file.
Problem Statement:
Let's enhance Lab so that it includes reading input from a file & throwing exceptions. The program will read from text files above that you can download and displays the output as shown below. The program should throw FileNotFoundException exception if files is not in the current directory. In addition, the two custom exception classes InvalidHourlyPayException & InvalidHoursException should be created. See example in Section Defining Custom Exception Classes. These exceptions should be thrown by the methods in the Employee class as shown on the UML diagram below and handled in the main class. The program should continue processing the data on the files only after verifying that the file exists, is not a directory, and can be read or exit if otherwise. Check methods in the File class such as exists isDirectory canRead The program must close files that are opened.
Employee class
Employee
MINHOURS: double
REGULARHOURS: double
MAXHOURS: double
MINHOURLYPAY: double
MAXHOURLYPAY: double
OVERTIMEPAY: double
name: String
employeeId: int
shift: Boolean
hourlyPay: double
hoursWorked: double
Employee
Employeen: String, i:int, s:Boolean, p:double, h : doublethrows InvalidHourlyPayException, InvalidHoursException
setNamen: String
setemployeeIDi:int
setShifts:Boolean
setHourlyPayp:double throws InvalidHourlyPayException
setHoursWorkedp:double throws InvalidHoursException
getname : String
getemployeeID : int
getShift : Boolean
getHoursWorked : double
getHourlyPay : double
calculateOvertimePay h : double : double throws InvalidHoursException
calculateRegPayh : double: double throws InvalidHoursException
printPayStub h : double throws InvalidHoursException
Your program should do the following :
Start
create array with the list of input files Example String myFileList empFiletxt "empFiletxt"empFiletxt "empFiletxt "empFiletxt;
Loop until each file in the array is run
instantiate a File object
verify file exists, is not a directory, or is readable
instantiate an Employee object
instantiate a scanner object
Note: Inputs that generate exception, as highlighted in the UML, must be within a try and catch block individually or together
Loop until there is no more employee record in the file
read and set employee name
read and set employee ID
read and set employee shift input "day" true input "night" false
read and set employee's hourly pay
read and set employee hourly pay
read and set hours the employee worked
display employee pay stub as shown in the example
End Loop
close opened files
End Loop
end
The program run should display the output shown below:
Employee Name: Ann
Employee ID:
Pay Period: Friday
Regular Pay: $
Overtime Pay: $
Gross Pay: $
Employee Name: Bob
Employee ID:
Pay Period: Saturday
Regular Pay: $
Overtime Pay: $
Gross Pay: $
Employee Name: Cara
Employee ID:
Pay Period: Friday
Regular Pay: $
Overtime Pay: $
Gross Pay: $
Employee Name: Don
Employee ID:
Pay Period: Saturday
Regular Pay: $
Overtime Pay: $
Gross Pay: $
InvalidHourlyPayException: Invalid hourly pay rate:
InvalidHourlyPayException: Invalid hourly pay rate:
InvalidHoursException: Invalid number of hours:
InvalidHoursException: Invalid number of hours:
Thank you for using the total pay Calculator!
Good Bye!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started