Requirements: 1. Name your code user.py. 2. Produce the required code to describe the User class per the UML Class Diagram requirements provided to you. a. Define the Class appropriately. Use object as the designated superclass. b. Code the constructor for the class as discussed in the demonstration videos posted to Blackboard. Use the correct, Python-defined name for the constructor method. Remember that the argument/parameter “self” is always included as the first argument/parameter in the constructor header/definition line. The attribute password will use a default value of “None”. That is, set the password attribute to null or None when no value is present for that argument/parameter. b. Code a mutator or set method for each listed attribute. Remember that the argument/parameter “self” is always included as the first argument/parameter in the mutator header/definition line. The only other parameter included should be a value of the appropriate type for the specific attribute. HINT: It would be smart to make certain that the value stored for the attribute employeeId is an integer. c. Code an accessor or get method for each listed attribute. Remember that the argument/parameter “self” is always included as the first argument/parameter in the accessor header/definition line. No other argument/parameter should ever be included in the accessor header/definition. NOTE: Check the value of the password attribute in the accessor method prior to returning a value. If no value has been set for password, return “NO PASSWORD SET”. d. Code a String method for the class. Use the correct, Python-defined name for the String method. Use the following format string to build the string returned by this method: ( "User: %‐20s%‐40s\n\tEmployee ID: %s" + “\n\tRole: %s\n\tPassword: %s/n") The second replacement value should be the name attribute. 3. Comment your code. a. Include a description of the class at the top of your code. b. Include comment(s) describing the purpose of the mutator/set methods. (If you group all mutator methods together, you may use a single block comment.) c. Include comment(s) describing the purpose of the accessor/get methods. (If you group all accessor methods together, you may use a single block comment.) d. Include a description for the String method. 4. Under NO CIRCUMSTANCES should your code include any input or output statements of any sort or type. If print statements are used for debugging, you must remove them (or comment out) prior to submission. Failure to adhere to this rule triggers a 20 point deduction from the rubric-determined score. 5. Test your User class to insure that it performs as expected. Be sure that you have tested all of the methods required/listed in the UML. The assignment materials include a batch test harness and a test case input file. Test Cases code: """ This is what is referred to as a "batch test harness". Essentially, that means that many test cases may be run in a single execution of the code. This method of testing is incredibly valuable when we must run many dozens (or hundreds or thousands) of test cases in order to validate code. """ from user import User # We must import the class definition #============================================================================= def main( ): """ The main function will essentially call other functions to do all the "heavy lifting". As usual, this funciton is the "traffic cop" directing the action rather than the one taking action. """ # Call a function to collect the test case and instantiate User objects testCases = getTestCases( ) # Use a for loop to check the User objects - Are they what we expect? print( "%50s" % "Testing String Method" ) for case in testCases: print( case ) # end for loop # end main Function #============================================================================= def getTestCases( ): """ This function will prompt for an input file name. (You are MORE THAN WELCOME TO CREATE YOUR OWN TEST CASES!) The file containing the test cases will be opened for reading. Each line represents a test case. The individual lines will be broken into their constituent pieces and those pieces will then be used to INSTANTIATE User objects for testing. """ caseFile = input( "Which file do you want to use for testing? " ) inputFile = open( caseFile, 'r' ) # Open the file for reading/input caseList = [ ] # Declare an empty List structure for line in inputFile: # Each line in the file = 1 test case line = line.strip( ) # Strip the newline character from input items = line.split( "," ) # Split into "parts" based on comma # Instantiate a User object for testing testCase = User( items[ 0 ], # userId items[ 1 ], # name items[ 2 ], # employeeNbr items[ 3 ], # role items[ 4 ] ) # password # Add the new User object to the List structure caseList.append( testCase ) # end for loop # Return the completed List structure to caller return caseList # end getTestCases Function #============================================================================ if __name__ == "__main__": main( )
Requirements:
1. Name your code user.py.
2. Produce the required code to describe the User class per the UML Class Diagram
requirements provided to you.
a. Define the Class appropriately. Use object as the designated superclass.
b. Code the constructor for the class as discussed in the demonstration videos posted
to Blackboard.
Use the correct, Python-defined name for the constructor method.
Remember that the argument/parameter “self” is always included as the
first argument/parameter in the constructor header/definition line.
The attribute password will use a default value of “None”. That is, set the
password attribute to null or None when no value is present for that
argument/parameter.
b. Code a mutator or set method for each listed attribute.
Remember that the argument/parameter “self” is always included as the
first argument/parameter in the mutator header/definition line.
The only other parameter included should be a value of the appropriate
type for the specific attribute.
HINT: It would be smart to make certain that the value stored for the
attribute employeeId is an integer.
c. Code an accessor or get method for each listed attribute.
Remember that the argument/parameter “self” is always included as the
first argument/parameter in the accessor header/definition line.
No other argument/parameter should ever be included in the accessor
header/definition.
NOTE: Check the value of the password attribute in the accessor method
prior to returning a value. If no value has been set for password, return
“NO PASSWORD SET”.
d. Code a String method for the class.
Use the correct, Python-defined name for the String method.
Use the following format string to build the string returned by this method:
( "User: %‐20s%‐40s\n\tEmployee ID: %s" +
“\n\tRole: %s\n\tPassword: %s/n")
The second replacement value should be the name attribute.
3. Comment your code.
a. Include a description of the class at the top of your code.
b. Include comment(s) describing the purpose of the mutator/set methods. (If you
group all mutator methods together, you may use a single block comment.)
c. Include comment(s) describing the purpose of the accessor/get methods. (If you
group all accessor methods together, you may use a single block comment.)
d. Include a description for the String method.
4. Under NO CIRCUMSTANCES should your code include any input or output statements of
any sort or type. If print statements are used for debugging, you must remove them (or
comment out) prior to submission. Failure to adhere to this rule triggers a 20 point
deduction from the rubric-determined score.
5. Test your User class to insure that it performs as expected. Be sure that you have tested
all of the methods required/listed in the UML.
The assignment materials include a batch test harness and a test case input file.
Test Cases code:
"""
This is what is referred to as a "batch test harness". Essentially, that
means that many test cases may be run in a single execution of the code.
This method of testing is incredibly valuable when we must run many dozens
(or hundreds or thousands) of test cases in order to validate code.
"""
from user import User # We must import the class definition
#=============================================================================
def main( ):
"""
The main function will essentially call other functions to do all the
"heavy lifting". As usual, this funciton is the "traffic cop" directing
the action rather than the one taking action.
"""
# Call a function to collect the test case and instantiate User objects
testCases = getTestCases( )
# Use a for loop to check the User objects - Are they what we expect?
print( "%50s" % "Testing String Method" )
for case in testCases:
print( case )
# end for loop
# end main Function
#=============================================================================
def getTestCases( ):
"""
This function will prompt for an input file name. (You are MORE THAN
WELCOME TO CREATE YOUR OWN TEST CASES!) The file containing the test
cases will be opened for reading. Each line represents a test case.
The individual lines will be broken into their constituent pieces and
those pieces will then be used to INSTANTIATE User objects for testing.
"""
caseFile = input( "Which file do you want to use for testing? " )
inputFile = open( caseFile, 'r' ) # Open the file for reading/input
caseList = [ ] # Declare an empty List structure
for line in inputFile: # Each line in the file = 1 test case
line = line.strip( ) # Strip the newline character from input
items = line.split( "," ) # Split into "parts" based on comma
# Instantiate a User object for testing
testCase = User( items[ 0 ], # userId
items[ 1 ], # name
items[ 2 ], # employeeNbr
items[ 3 ], # role
items[ 4 ] ) # password
# Add the new User object to the List structure
caseList.append( testCase )
# end for loop
# Return the completed List structure to caller
return caseList
# end getTestCases Function
#============================================================================
if __name__ == "__main__":
main( )
Trending now
This is a popular solution!
Step by step
Solved in 2 steps