Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me make this Python script? Your script should contain the two class

ID: 3815736 • Letter: P

Question

Please help me make this Python script?

Your 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.

The constructor must have the following header

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

Your script must contain the following test code

Your output should look something like this

Explanation / Answer

# Pastebin link for code in case indentation mess up: https://pastebin.com/PCL1jni8

class Employee(object):
def __init__(self, name, number):
self.name = name
self.number = number
  
def get_name(self):
return self.name
  
def get_number(self):
return self.number

class ProductionWorker (Employee):
def __init__(self, name, number):
super(ProductionWorker, self).__init__(name, number)
self.shift = 1
self.rate = 15.0
  
def get_shift(self):
return self.shift
  
def get_rate(self):
return self.rate
  
def set_shift(self, shift):
try:
shift = int(shift)
if shift >= 1 and shift <= 3:
self.shift = shift
else:
print("shift can only be 1, 2 or 3")
except:
print(str(shift) + " cannot be converted into an integer")
  
def set_rate(self, rate):
try:
rate = float(rate)
if rate >= 15.0 and rate <= 50.0:
self.rate = rate
else:
print ("rate must be between 15.00 and 50.00")
except:
print(str(rate) + " cannot be converted into a float")
  
def __str__(self):
return self.name + ", " + str(self.number) + ", shift: " + str(self.shift) + ", rate: $" + str(self.rate)
  

def main():
e1 = Employee("Frank", 1)
print(e1.get_name(), e1.get_number())
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)
  
if __name__ == "__main__":
main()

Sample execution:

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

Please rate positively if this solved your question.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote