Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main() method. Within the same file, create another class named

Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main() method. Within the same file, create another class named Employee, and do not declare it public. Create a field for each of the following pieces of information: employee name, employee number, hourly pay rate, and overtime rate. Create accessor and mutator methods for each field. The mutator method for the hourly pay rate should require the value to be greater than zero. If it is not, set the rate to zero. The overtime rate must be an integer value of zero or higher. If an attempt is made to set it negative, simply set it to zero. Create a constructor that accepts four arguments and calls each mutator method, passing the appropriate argument to each method. Create a method named CalculateWage() that returns the employees weekly wage. The method must accept two arguments, each of which is described below. The first argument should hold the number of hours the employee worked over the pay period. The number of hours worked must be zero or higher. If the value passed to the method is less than zero, display a message that says the number of hours is invalid and return a -1. Note: An even better option is to create and throw an Exception. If youre familiar with Exceptions, feel free to do so anywhere you find appropriate. The second argument should hold the shift number that the employee worked. An employee can work first, second, or third shift. Display an error message and return -1 if an attempt is made to set the value to something other than 1, 2, or 3. Employees who work third shift are paid 10% above their hourly pay rate. Here are a few examples of how the method should work. Suppose an employee works first shift for 45 hours and that he makes 15% extra for overtime. In this case, he would earn 40 * 20 + 5 * 20 * 1.15 = $915. Now suppose that same employee works third shift for 45 hours instead of first. He would then receive 40 * 20 * 1.10 + 5 * 20 * 1.25 = $1,005. In the main() method, prompt the user for an employee name, number, an hourly pay rate, and a percentage paid for overtime. Using these values, instantiate a new Employee object. Then, prompt the user to provide the number of hours the employee worked, the shift he worked them on, and the percentage paid for overtime. Call the Employee objects CalculateWage() method, passing the relevant values to it. If the values are valid, display the earnings for the employee. Continue prompting the user for the hourly pay rate, shift, hours worked, and percentage for overtime hours. Use the values to calculate the weekly pay in a loop until the user decides to quit, at which point the program should end. Note: Do not create a new Employee object each time within the loop. If any of the objects attributes need to change, simply call the appropriate mutator method to change it. When finished with your work, be sure to fully comment your program. Submit it in Blackboard on or before the deadline.

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

Oracle PL/SQL Programming Database Management Systems

Authors: Steven Feuerstein

1st Edition

978-1565921429

More Books

Students also viewed these Databases questions