Question: For this program, you will create a class called Employee . This class will have attributes for a first name, last name, employee ID, the

For this program, you will create a class called Employee. This class will have attributes for a first name, last name, employee ID, the pay rate of the employee and the hours worked by the employee.

You will have a constructor method that initializes the attributes. Initialize the first name and last name to upper and other attributes not passed to the constructor method to their null value.

You will need get (accessor) and set (mutator) methods for the appropriate attributes. You will also have a get (accessor) method that returns the gross pay. You will need to have a decision in this method. If hours worked are over 40 then the employee gets paid 1.5 times their pay rate for any hours over 40. For example, if the employee worked 45 hours and makes $15.50 an hour, the gross pay is:

(40 * 15.5) + (5 * 23.25) = 736.25

You will also have a _str_ _ method to show the state of each object. The format for the state of the object is illustrated in Figure 2 above. Basically, this will show the output (formatted) for each instance of the object. In this method, you will call two other get methods. One method will concatenate the first and last name with a space in between. The other method will have the social security number only show the last 4 digits (see Figure 2).

Store the class in a python module file called "employee" (this is the name of the class file, per above the class is named "Employee").

Write a program that imports the class. You will also need to import the "pickle" module for this assignment (this is from the end of Chapter 9).

In this main function you will call two functions:

EmployeeInfo

ShowData

In the EmployeeInfo function you will need to open a .dat (binary) file to write to. You will loop in this function asking the user for the information for the class, as illustrated by the inputs in Figure 1 above.

As you can see above, you need to prompt for the first name, last name, ID, pay rate and hours worked. If the user does not type in 9 digits for the social security number (ID) the program should tell the user the ID MUST be 9 characters (and only 9 characters) in length. The user should be able to enter as many employees as they want. Each time they enter all the input, an instance of the class should be created and then this should be dumped into the file. Once the user is done entering products do not forget to then close the file.

In the ShowData function, the user should open the binary file created in the first function for reading from. Print headings per Figure 2. Loop through the file (until end of file) and each time through the loop, load an Employee object from the file. Use the class to generate the output shown in Figure 2 (this will use the _ _str_ _ method to show output).

When you code these programs make sure to use proper variable naming and add comments to the program. Variable naming and function naming conventions were outlined in Activity 2.1: Python Program Lists (Program 1). Comments should include:

A comment introducing the class and the program

Section comments for each section of the class and introducing each function of the program

Line comments for non-obvious code (such as loops and decisions)

In the first function in the program (EmployeeInfo), you will need to use exception handling for pay rate and hours worked.

Please make sure you complete your own work. There is no possible way two people can create the exact same program code. Remember, if you share your files both the student who submitted another student's file and the person who gave the file to that student will get a zero (0) on the assignment.

For this program, you will create a class called Employee. This class

will have attributes for a first name, last name, employee ID, the

Enter a an employee first name: George Enter the last name of employee George: Miller Enter George Miller's social security number (it must be 9 digits) : 23456456 The social security number MUST be 9 digits in length Please enter again Enter George miller's social security number (it must be 9 digits): 234564567 Enter the pay rate of the employee $15.5 Enter the hours worked by the employee: 45

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!