IT 117: Introduction to Scripting
Homework 11

Due

Sunday, April 23rd at 11:59 PM

Deliverables

There is one deliverable for this assignment

Make sure the script obeys all the rules in the Script Requirements page.

Specification

The script must have have two classes, Game and Baseball_Game.

Baseball_Game is a subclass of Game.

Game

Game will have the following attributes

All attributes must be hidden.

Game must have the following methods

__init__

This method must have the following header

def __init__(self, date, home_team, opponent, home_score, opponent_score):

__str__

This method must return a string containing the values of all attributes.

winner

This method must return the name of the winning team.

Baseball_Game

Baseball_Game will have the following attributes

All attributes must be hidden.

Baseball_Game

Baseball_Game must have the following methods

__init__

This method must have the following header

def __init__(self, date, home_team, opponent, home_score, opponent_score, winning_pitcher):

__str__

This method must return a string containing the values of 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:

game_1 = Game("2007-10-24", "Red Sox", "Rockies", 13, 1)
print(game_1)
print(game_1.get_date())
print(game_1.get_home_team())
print(game_1.get_home_score())
print(game_1.get_opponent())
print(game_1.get_opponent_score())
print(game_1.winner())
game_2 = Baseball_Game("2007-10-24", "Red Sox", "Rockies", 13, 1, "Josh Beckett" )
print(game_2)
print(game_2.get_winning_pitcher())

Run the script.

You should see

$ ./hw11.py 
2007-10-24: Red Sox 13, Rockies 1
2007-10-24
Red Sox
13
Rockies
1
Red Sox
2007-10-24: Red Sox 13, Rockies 1, Winning pitcher: Josh Beckett

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 Game.
    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. Write __str__.
    Remove the # from the 2nd line of the test code.
    Run the script.
    Fix any errors you find.
  3. Write get_date.
    Remove the # from the 3rd line of the test code.
    Run the script.
    Fix any errors you find.
  4. Write get_home_team.
    Remove the # from the 4th line of the test code.
    Run the script.
    Fix any errors you find.
  5. Write get_home_score.
    Remove the # from the 5th line of the test code.
    Run the script.
    Fix any errors you find.
  6. Write get_opponent.
    Remove the # from the 6th line of the test code.
    Run the script.
    Fix any errors you find.
  7. Write get_opponent_score.
    Remove the # from the 7th line of the test code.
    Run the script.
    Fix any errors you find.
  8. Write winner.
    Remove the # from the 8th line of the test code.
    Run the script.
    Fix any errors you find.
  9. Write the class header for Baseball_Game.
    Write the constructor for this class.
    Remove the # from the 9th line of the test code.
    Run the script.
    Fix any errors you find.
  10. Write __str__.
    Remove the # from the 10th line of the test code.
    Run the script.
    Fix any errors you find.
  11. Write get_winning_pitcher.
    Remove the # from the last line of the test code.
    Run the script.
    Fix any errors you find.

Testing on Your Machine

Unix Setup

Copy the file to Unix

Testing the script on Unix

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