Lab 8

Introduction:

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.

Product Class

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:

Be 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:

  1. Create a Product object for lamps, with field values:
    • Name: Lamp
    • Quantity: 5000
    • Price: $25
    Use the constructor to set those values.
  2. Create a Product object for chairs, with field values:
    • Name: Chair
    • Quantity: 8000
    • Price: $15
  3. Create a second Product object for lamps, with field values:
    • Name: Lamp
    • Quantity: 5000
    • Price: $25
    After creating the object, use the appropriate set methods to change the quantity to 5500 and price to $23.
  4. Print out each of the objects created above. Make use of the special method for each object.
  5. Compare the first object created (the Lamp) to the second object created (the Chair with quantity 8000) using the equals method. If the two objects are equal, print out "The first and second product are equal."
  6. Compare the first object created (the lamps with quantity 5000) to the third object created (the lamps with quantity 5500) using the equals method. If the two objects are equal, print out "The first and third product are equal."

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.

Submission and Grading:

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.