IT 117: Intermediate Scripting
Homework 11

Due

Sunday, April 27th at 11:59 PM

What You Need to Do

Setup On Your Machine

Specification

Classes

Employee

ProductionWorker

Test Code

Output

Suggestions

  1. Add a header for the class Employee to the script.
    Create the method header for the constructor __init__ with parameters self, name and number.
    For the body of this function, use a pass statement.
    Run the script and fix any errors you find.
  2. Copy the test code to the bottom of the script.
    Comment out all the statements after
    e1 = Employee("Frank", 1)
    Add assignment statements for each of the attributes.
    Remember the attributes must be hidden.
    Run the script and fix any errors you find.
  3. Creates the accessor methods get_name and get_number.
    Uncomment the next line in the test code.
    Run the script and fix any errors you find.
  4. Create method __str__ that returns a string containing the value of all attributes with a comma between them. Remember to convert number into a string.
    Remove the # from the next two lines in the test code. Run the script and fix any errors you find.
  5. Add a header for the subclass ProductionWorker to the script.
    Create the method header for the constructor __init__ with parameters self, name and number.
    For the body of this function, use a pass statement.
    Run the script and fix any errors you find.
  6. You need to call the Employee constructor to set the values for name and number.
    This is done with the following statement
    Employee.__init__(self, name, number)
    Assign shift the vale 1.
    Assign rate the vale 15.00.
    Uncomment the next line in the test code.
    Run the script and fix any errors you find.
  7. Creates the accessor methods get_shift and get_rate.
    Uncomment the next line in the test code.
    Run the script and fix any errors you find.
  8. Create the mutator method set_shift that changes the value for shift.
    This number must be an integer, so you will have to convert it.
    But the conversion could fail, so you will have to do it inside a try/except statement.
    Write a try/except statement.
    In the try block write an assignment statement that converts the new value into an integer.
    Now that the value has been converted, we must make sure its value is either 1, 2 or 3.
    Write an if statement that checks whether the converted value is in the list [1,2,3].
    If it is, asign this convereted value to the attribute shift.
    In the else block of the if statement print an error message saying the value must be ether 1, 2 or 3.
    In the except block print an error message that the value could not be converted into an integer.
    Uncomment the lines down to and including
    print('shift:', e2.get_shift())
    Run the script and fix any errors you find.
  9. Create the mutator method set_rate that changes the value for rate.
    This number must be a float, so you will have to convert it.
    Since the conversion could fail, you will have to do it inside a try/except statement.
    Write a try/except statement.
    In the try block write an assignment statement that converts the new value into a float.
    We must check that the new value is in right range.
    Write an if statement that checks whether the converted value greater than or equal to 15 and less than or equal to 50.
    If it is, asign this convereted value to the attribute rate.
    In the else block of the if statement print an error message saying the value must be between 15 and 50.
    In the except block print an error message that the value could not be converted into a float. Uncomment the all the lines in the test code, except the last. Run the script and fix any errors you find.
  10. Create __str__ method that returns a string containing the value of all attributes with a comma between them.
    Remember to convert number, shift and rate to strings.
    Remove the # from the last line in the test code.
    Run the script and fix any errors you find.

Testing on Your Machine

Copy the Script to Unix

Testing the Script on Unix (Optional)

Copyright © 2022 Glenn Hoffman. All rights reserved. May not be reproduced without permission.