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

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

__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

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

  1. 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.
  2. 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.
  3. Create the __str__ method.
    Uncomment the next line in the test code.
    Run the script.
    Fix any errors you find.
  4. 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
  5. 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.
  6. Create the __str__ method.
    Uncomment the last line in the test code.
    Run the script.
    Fix any errors you find.

Testing on Your Machine

Copy the file to Unix

Make the File Executable

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