Question: Write a Java application that will read in a binary file containing objects of HourlyEmployee type and create the weekly payroll. The payroll should be

Write a Java application that will read in a binary file containing objects of HourlyEmployee type and create the weekly payroll. The payroll should be written to a text file containing the hourly employee name and the pay for the week. The application should compute the weekly pay for each employee. The regular pay is the wageRate multiplied by hours worked less than or equal to 40 hours. For overtime pay, the wageRate should be multiplied by 1.5 for all hours worked over 40 hours. The file Payroll.java contains a skeleton of the program. Do the following:

1. Set up a ObjectInputStream object infile from the input file and a PrintWriter outFile to the output file inside the try clause (see the comments in the program). Note that youll have to create the PrintWriter from a FileWriter, but you can still do it in a single statement.

2. Inside the while loop add code to read the input file. Dont forget to cast each object to HourlyEmployee

. 3. Compute the weekly pay, then write the employee name and weekly pay to the output file.

4. After the loop close the PrintWriter.

5. Think about the exceptions that could be thrown by this program: An EOFException when the end of file has been reached A FileNotFoundException if the input file does not exist A ClassNotFoundException if the object class files does not exist An IOException if something else goes wrong with the input or output stream Add a catch for each of these situations, and in each case give as specific a message as you can. The program will terminate if any of these exceptions is thrown, but at least you can supply the user with useful information.

6. Test the program. Test data is in the file hourly.dat. Be sure to test each of the exceptions as well.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!