IT 117: Introduction to Scripting
Homework 9
Due
Sunday, April 9th 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
In your hw9.py define the class LP that has the following attributes
- title
- label
- artist
- released
The class must have the following methods
- get_title
- get_label
- get_artist
- get_released
- __str__
All the attributes in this class MUST be hidden.
get_title
This method returns the value of the title attribute.
get_label
This method returns the value of the label attribute.
get_artist
This method returns the value of the artist attribute.
get_released
This method returns the value of the released attribute.
__str__
This method returns a string consisting of the value of the title attribute,
followed by a comma and a space, the value of the label
attribute,
followed by a comma and a space, and the value of the artist
attribute.
Script for this assignment
Open an a text editor and create the file
hw9.py.
You can use the editor built into IDLE or a program like Sublime.
Test Code
Your hw9.py file must contain the following test code at the
bottom of the file:
lp = LP("The London Concert", "Sony Classical", "Wynton Marsalis", "1994")
print(lp.get_title())
print(lp.get_label())
print(lp.get_artist())
print(lp.get_released())
print(lp)
You should see
$ ./hw9.py
The London Concert
Sony Classical
Wynton Marsalis
1994
The London Concert, Sony Classical, Wynton Marsalis, 1994
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.
- Make a copy of your hw8.py file in your hw9
directory.
Change the name of this file to hw9.py
Remove all the test code from hw9.py
Run the script.
You should see nothing.
Fix any problem you find.
- Change __init__ by adding the parameter released.
Copy the first line of the test code to the bottom of your script.
Run the script.
You should see nothing.
Fix any problem you find.
- Change __init__ and get_title so the attribute
title is hidden.
Copy the 2nd line of the test code to the bottom of your script.
Run the script.
Fix any problem you find.
- Change __init__ and get_label so the attribute
label is hidden.
Copy the 3rd line of the test code to the bottom of your script.
Run the script.
Fix any problem you find.
- Change __init__ and get_artist so the attribute
artist is hidden.
Copy the 4th line of the test code to the bottom of your script.
Run the script.
Fix any problem you find.
- Change __init__ so it sets the value of the attribute released.
Create the method get_released that returns the value of this attribute.
Copy the 5th line of the test code to the bottom of your script.
Run the script.
Fix any problem you find.
- Remove the method print_lp.
Replace it with the method __str__ which
returns a string containing the values of each of the attributes.
Copy the last line of the test code to the bottom of your script.
Run the script.
Fix any problem you find.
Testing on Your Machine
- Open IDLE
- Use the Open command in IDLE to open hw9.py
- Under the Run menu, select Run Module
- Your output should look something like this
The London Concert
Sony Classical
Wynton Marsalis
1994
The London Concert, Sony Classical, Wynton Marsalis, 1994
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 hw9
- 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/hw9
Testing the script on Unix
- Connect to
Use an ssh client.
- Go to the directory for this exercise
cd it117/hw/hw9
- Make this script executable
chmod 755 hw9.py
- Run this script
./hw9.py
- You should see something like
The London Concert
Sony Classical
Wynton Marsalis
1994
The London Concert, Sony Classical, Wynton Marsalis, 1994
- 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.