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
- date
- home_team
- opponent
- home_score
- opponent_score
All attributes must be hidden.
Game must have the following methods
- __init__
- get_date
- get_home_team
- get_home_score
- get_opponent
- get_opponent_score
- __str__
- winner
__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__
- __str__
- get_winning_pitcher
__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.
- 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.
- Write __str__.
Remove the # from the 2nd line of the test code.
Run the script.
Fix any errors you find.
- Write get_date.
Remove the # from the 3rd line of the test code.
Run the script.
Fix any errors you find.
- Write get_home_team.
Remove the # from the 4th line of the test code.
Run the script.
Fix any errors you find.
- Write get_home_score.
Remove the # from the 5th line of the test code.
Run the script.
Fix any errors you find.
- Write get_opponent.
Remove the # from the 6th line of the test code.
Run the script.
Fix any errors you find.
- Write get_opponent_score.
Remove the # from the 7th line of the test code.
Run the script.
Fix any errors you find.
- Write winner.
Remove the # from the 8th line of the test code.
Run the script.
Fix any errors you find.
- 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.
- Write __str__.
Remove the # from the 10th line of the test code.
Run the script.
Fix any errors you find.
- 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
- 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
Unix Setup
- Log in to users3.cs.umb.edu
You will be in your home directory.
- Go to your it117 directory
cd it117
- Go to your hw directory
cd hw
- Create a directory for this exercise
mkdir hw11
- Check that the directory was created
ls
Copy the file to Unix
- Open FileZilla and connect to
users3.cs.umb.edu
You will have to connect using your Unix username and password.
- Copy the file to the to it117/hw/hw11
Testing the script on Unix
- Connect to
Use an ssh client.
- Go to the directory for this exercise
cd it117/hw/hw11
- Make this script executable
chmod 755 hw11.py
- Run this script
./hw11.py
- You should see
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
- If your script does not run on users3
you will lose points
Copyright © 2020 Glenn Hoffman. All rights reserved. May not be reproduced without permission.