Answered step by step
Verified Expert Solution
Link Copied!

Question

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 MIN_HOURLY_PAY or above MAX_HOURLY_PAY
InvalidHoursException.java that can be thrown if the number of hours employee worked is below MIN_HOURS or above MAX_HOURS
Download and use the following text files to test your program
empFile1.txtDownload empFile1.txt
empFile2.txtDownload empFile2.txt
empFile3.txtDownload empFile3.txt
empFile4.txtDownload empFile4.txt
empFile5.txtDownload empFile5.txt
Submission Instruction
Submit Employee.java file
Submit InvalidHourlyPayException.java file.
Submit InvalidHoursException.java file.
Submit EmployeeExceptionHandling.java file.
Problem Statement:
Let's enhance Lab 10 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 12.9 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
+MIN_HOURS: double =1
+REGULAR_HOURS: double =40
+MAX_HOURS: double =80
+MIN_HOURLY_PAY: double =1
+MAX_HOURLY_PAY: double =100
+OVER_TIME_PAY: double =1.5
-name: String
-employeeId: int
-shift: Boolean
-hourlyPay: double
-hoursWorked: double
+Employee()
+Employee(n: String, i:int, s:Boolean, p:double, h : double)throws InvalidHourlyPayException, InvalidHoursException
+setName(n: String)
+setemployeeID(i:int)
+setShift(s:Boolean)
+setHourlyPay(p:double) throws InvalidHourlyPayException
+setHoursWorked(p:double) throws InvalidHoursException
+getname() : String
+getemployeeID() : int
+getShift() : Boolean
+getHoursWorked() : double
+getHourlyPay() : double
+calculateOvertimePay( h : double) : double throws InvalidHoursException
+calculateRegPay(h : 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 ={"empFile1.txt", "empFile2.txt","empFile3.txt", "empFile4.txt", "empFile5.txt"};
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 file(s)
End Loop
end
The program run should display the output shown below:
Employee Name: Ann
Employee ID: 661448
Pay Period: Friday
Regular Pay: $2000.00
Overtime Pay: $75.00
Gross Pay: $2075.00
Employee Name: Bob
Employee ID: 558036
Pay Period: Saturday
Regular Pay: $2000.00
Overtime Pay: $0.00
Gross Pay: $2000.00
Employee Name: Cara
Employee ID: 234995
Pay Period: Friday
Regular Pay: $1500.00
Overtime Pay: $0.00
Gross Pay: $1500.00
Employee Name: Don
Employee ID: 886898
Pay Period: Saturday
Regular Pay: $3960.00
Overtime Pay: $5791.50
Gross Pay: $9751.50
InvalidHourlyPayException: Invalid hourly pay rate: 0.0
InvalidHourlyPayException: Invalid hourly pay rate: 101.0
InvalidHoursException: Invalid number of hours: 0.0
InvalidHoursException: Invalid number of hours: 81.0
Thank you for using the total pay Calculator!
Good Bye!

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