IT 117: Introduction to Scripting
Homework 10

Due

Sunday, April 16th 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 hw10.py define the class Wine that has the following attributes All the attributes in this class MUST be hidden.

The class must have the following methods

__init__

This method must have the following header:

def __init__(self, vineyard, type, year):
The constructor should set the value of rating to the empty string.

get_vineyard

This method must have the following header:

def get_vineyard(self):
Returns the value of vineyard.

get_type

This method must have the following header:

def get_type(self):
Returns the value of type.

get_year

This method must have the following header:

def get_year(self):
Returns the value of year.

get_rating

This method must have the following header:

def get_rating(self):
Returns the value of rating.

set_rating

This method must have the following header:

def set_rating(self, rating):
Assigns a value to the rating attribute.

__str__

This method must have the following header:

def __str__(self):
Returns a string containing all attribute values.

__gt__

This method must have the following header:

def __gt__(self, other):
Returns True if the the object's value for year is greater than the other object's value for year.

__lt__

This method must have the following header:

def __lt__(self, other):
Returns True if the the object's value for year is less than the other object's value for year.

__eq__

This method must have the following header:

def __eq__(self, other):
Returns True if the the object's value for year is equal to the other object's value for year.

__ne__

This method must have the following header:

def __ne__(self, other):
Returns True if the the object's value for year is not equal to the other object's value for year.

Script for this assignment

Open an a text editor and create the file hw10.py.

You can use the editor built into IDLE or a program like Sublime.

Test Code

Your hw10.py file must contain the following test code at the bottom of the file:

w1 = Wine("Pahkmeyer", "Merlot", 1999)
print("vineyard: ", w1.get_vineyard())
print("type:    ", w1.get_type())
print("year:    ", w1.get_year())
print("rating:  ", w1.get_rating())
w1.set_rating(95)
print(w1)
print("rating:  ", w1.get_rating())
w2 = Wine("Hartwell", "Merlot", 2000)
print(w2)
print("w1 > w2  :", w1 > w2)
print("w1 < w2  :", w1 < w2)
print("w1 == w2 :", w1 == w2)
print("w1 != w2 :", w1 != w2)

You should see

$ ./hw10.py 
vineyard:  Pahkmeyer
type:     Merlot
year:     1999
rating:   
Pahkmeyer Merlot 1999
rating:   95
Hartwell Merlot 2000
w1 > w2  : False
w1 < w2  : True
w1 == w2 : False
w1 != w2 : True

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 hw10.py.
    Write the class header for Wine.
    Write the constructor for this class.
    Make sure the constructor sets the value for each attribute, including rating.
    The value for year should be stored as an integer.
    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 get_vineyard.
    Uncomment the 2nd line of the test script by removing the #.
    Run the script.
    Fix any errors you find.
  3. Create get_type.
    Uncomment the 3rd line of the test script.
    Run the script.
    Fix any errors you find.
  4. Create get_year.
    Uncomment the 4th line of the test script.
    Run the script.
    Fix any errors you find.
  5. Create get_rating.
    Uncomment the 5th line of the test script.
    Run the script.
    Fix any errors you find.
  6. Create set_rating.
    Uncomment the next two lines of the test script.
    Run the script.
    Fix any errors you find.
  7. Create __str__.
    Uncomment the next three lines of the test script.
    Run the script.
    Fix any errors you find.
  8. Create __gt__ which returns True if the year of the object is greater than the year of the other object.
    Uncomment the next line of the test script.
    Run the script.
    Fix any errors you find.
  9. Create __lt__ which returns True if the year of the object is less than the year of the other object.
    Uncomment the next line of the test script.
    Run the script.
    Fix any errors you find.
  10. Create __eq__ which returns True if the year of the object is equal the year of the other object.
    Uncomment the next line of the test script.
    Run the script.
    Fix any errors you find.
  11. Create __ne__ which returns True if the year of the object is not equal the year of the other object.
    Uncomment the next line of the test script.
    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.