Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Statement: Let's enhance Lab 1 0 so that it includes reading input from a file & throwing exceptions. The program will read from text

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!
image text in transcribed

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

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions

Question

Predict the organic product(s) of this reaction. H CI H H base

Answered: 1 week ago

Question

List the steps in the control process.

Answered: 1 week ago

Question

Address an envelope properly.

Answered: 1 week ago

Question

Discuss guidelines for ethical business communication.

Answered: 1 week ago