IT 117: Introduction to Scripting
Homework 11
Due
Sunday, November 24th at 11:59 PM
Deliverables
There is one deliverable for this assignment
Make sure the script obeys all the rules in
Homework Script Rules
Specification
The script must define two classes
- Collectable
- Baseball_Card
Baseball_Card is a subclass of Collectable
Collectable
Collectable must have the following attributes
purchased and price
MUST be stored as integers
All attributes must be hidden.
purchased and price must be
stored as integers.
Collectable must have the following methods
- __init__
- get_type
- get_purchased
- get_price
- __str__
__str__ must return a string containing all attributes.
Baseball_Card
Baseball_Card must have the following attributes.
All attributes must be hidden.
year and must be stored as an integer.
Baseball_Card must have the following methods
- __init__
- get_player
- get_year
- get_company
- __str__
__str__ must return a string containing all attributes.
Script for this assignment
Open an a text editor and create the file
hw11.py.
You can use the editor built into IDLE or a program like Sublime.
Test Code
Your hw11.py file must contain the following test code at the
bottom of the file:
col_1 = Collectable("Baseball card", 2018, 500)
print(col_1.get_type())
print(col_1.get_purchased())
print(col_1.get_price())
print(col_1)
bc_1 = Baseball_Card("Willie Mays", 1952, "Topps", 2018, 500)
print(bc_1.get_player())
print(bc_1.get_year())
print(bc_1.get_company())
print(bc_1)
Suggestions
Write this program in a step-by-step fashion using the technique of
incremental development.
In other words, write a bit of code, test it, make whatever changes you need to get it
working, and go on to the next step.
-
Create the file hw11.py.
Write the class header for Collectable.
Write the constructor for this class.
Copy the test code to the bottom of the script.
Comment out all line in the test code except the first.
You comment out a line by making # the first character on the line.
Run the script.
Fix any errors you find.
-
Create the methods get_type, get_purchased and
get_price.
Uncomment the next three lines in the test code.
Run the script.
Fix any errors you find.
-
Create the __str__ method.
Uncomment the next line in the test code.
Run the script.
Fix any errors you find.
-
Write the class header for Baseball_Card.
Write the constructor for this class.
When you call the __init__ method for Collectable
you will have to supply the string "Baseball card" as the second argument.
Uncomment the next line in the test code.
Run the script.
Fix any errors you find
-
Create the methods get_player, get_year and
get_company.
Uncomment the next three lines in the test code.
Run the script.
Fix any errors you find.
-
Create the __str__ method.
Uncomment the last line in the test code.
Run the script.
Fix any errors you find.
Testing on Your Machine
- Open IDLE
- Use the Open command in IDLE to open hw11.py
- Under the Run menu, select Run Module
- Your output should look something like this
Baseball card
2018
500
Baseball card, 2018, 500
Willie Mays
1952
Topps
Willie Mays, 1952, Topps, Baseball card, 2018, 500
Copy the file to Unix
- Open FileZilla and connect to
pe15.cs.umb.edu
You will have to connect using your Unix username and password.
- Go to your 117 directory
- Go to your hw directory
- Inside this directory create the directory hw11
- Copy your hw11.py file from your machine to the
hw11 directory on pe15
Make the File Executable
- Connect to pe15.cs.umb.edu
Use an ssh client.
- Go to your it117 directory
cd 117
- Go to your hw directory
cd hw
- Go to your hw11 directory
cd hw11
- Change the permissions on the script
chmod 755 hw11.py
Copyright © 2021 Glenn Hoffman. All rights reserved. May not be reproduced without permission.