In this lab, you will practice writing a class, with fields and methods. You will also create instances of the class and work with them.
Design and program a Product
class (named Product
) that represents an item for sale. The class must contain the following fields:
Your class must also provide the following methods:
set_name
, get_name
set_quantity
, get_quantity
set_price
, get_price
get_quantity
and get_price
methods should return a number.
get_price_str
method that returns the price as a string, formatted to look like a dollar amountProduct
objects are equal; it determines if they're equal by comparing the names (ignoring capitalization)Product
object into a nicely-printable string (see the Special Method Names section of Python's documentation); the string should contain the name, price (formatted as a dollar amount), and quantityBe sure to properly document your methods. The class must maintain encapsulation and data abstraction.
Demonstrate that your class behaves as described by writing a program in a separate file. The program must have the following steps:
Product
object for lamps, with field values:
Product
object for chairs, with field values:
Product
object for lamps, with field values:
The graders will have their own program to test your Product
class. Be sure to test your Product
class on more than just the program described above.
Complete the Assignment Information Sheet.
Submit your final program and assignment information sheet (zipped into one file) to CourseWeb in the Lab 8 assignment.
The grading rubric can be found here: Rubric (doc).
The assignment is due Monday, July 20 by 11:30 am. As with all programming assignments, you have unlimited uploads (before the deadline), so you may upload the assignment before the deadline. If you later decide to upload another, you may do so without penalty (as long as it's before the assignment deadline). The last submission uploaded before the deadline will be the one graded. If you would like ungraded feedback on a programming assignment, you may send an email to your TA or the instructor and ask for feedback; please send your code as well.
For more advice on submitting your assignment, see the Programming Assignments section of the Tips for Success page.