Question
Python3, for __str__ function, do NOT use call to format and use getters instead I want only ONE Frank 1 in the output. Your hw11.py
Python3, for __str__ function, do NOT use call to format and use getters instead
I want only ONE Frank 1 in the output.
Your hw11.py script should contain the two classes below as well as the test code.
Employee Class
Create the class Employee with two hidden attributes
name
number
This class will only have a constructor, an __str__ method and getters for the two attributes. The constructor must have the following header
def __init__(self, name, number):
ProductionWorker Class
Create the class ProductionWorker which is a subclass of Employee. This constructor must have the same header as the one for Employee. The constructor must call the Employee. The constructor must also set two hidden attributes to their default values.
shift - 1
rate - 15.00
The class must have the following accessor methods
get_shift
get_rate
The class must have an __str__ method which returns a string containing all the attributes. The class must also have the mutator set_shift which will only accept integers of 1, 2 and 3, and will print an error message if given a value that cannot be turned into an integer or a value other than the ones given above and leave the original value in place. The class must have the mutator set_rate which will only accept a float value in the range 15.00 to 50, and will print an error message if given a value that cannot be turned into an integer or a value outside the range and leave the original value in place.
Suggestions
Testing
Your output should look something like this
Be sure to run this script on the Unix machine so you know it works in the environment in which I will run it when I score your homework. Your script must contain the following test code
if __name__ == '__main__': e1 = Employee("Frank", 1) print(e1.get_name(), e1.get_number()) print(e1) print() e2 = ProductionWorker('Sam', 2) print(e2.get_name(), e2.get_number(), e2.get_shift(), e2.get_rate()) e2.set_shift('one') print('shift:', e2.get_shift()) e2.set_shift(4) print('shift:', e2.get_shift()) e2.set_shift(2) print('shift:', e2.get_shift()) e2.set_rate('twenty') print('rate:', e2.get_rate()) e2.set_rate(10) print('rate:', e2.get_rate()) e2.set_rate(20) print('rate:', e2.get_rate()) print(e2)
Your output should look something like this
$ ./hw07.py Frank 1 Sam 2 1 15.0 one cannot be converted into an integer shift: 1 shift can only be 1, 2 or 3 shift: 1 shift: 2 twenty cannot be converted into a float rate: 15.0 rate must be between 15.00 and 50.00 rate: 15.0 rate: 20.0 Sam, 2, shift: 2, rate: $20.0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started