ITEC 120 Back to Assignment index page
   
Assignment 3 - Item
Due Wednesday, April 5, midnight. Submit your program to the RU07 folder in your directory on neelix.

Description:  You'll design and write a class to represent a grocery store item, and a driver to test it.

The Item class:
Write a class which represents an item in a grocery store.

Characteristics of a grocery store item:

Things a grocery store item must be able to do (methods):

The driver:
The driver will simply test the class and it's methods. Create objects, print them out, test all your methods, print things that show all the methods work as planned.

NOTES : There are two different types of items -- items sold by weight and items which simply have a price. Therefore, the price stored in the object can mean two different things. For items sold by weight, price means price per pound. (Items sold by weight have a 5 as the last digit of the item number.) Other items just have a price which is the price. This means that several different methods have to take this into account. For example, the toString method should return a string like this:

456925  Apples, Fuji              2.32 pounds @ $1.29 per pound     $2.99

or:

456920  Cracker Jacks, 12 oz.                                       $2.49

depending on whether the item is sold by weight (apples) or not (Cracker Jacks).

Similarly, the getPrice method will have to figure out if the item is sold by weight. In the apple example above, the price stored in the object would be 1.29, and the price returned by the getPrice method would be 2.99.

One of the premises of object oriented design is that is should be impossible to create invalid objects or have invalid data. So, the constructors should check to make sure that if the item has a weight, the last digit of the item number is 5. The other constructor, which sets the weight to 0, should make sure that the item number does NOT end in 5. Your constructors should print an error message if there is an error with the item number. (A better way to handle this is for the constructors to throw an exception if there is a problem, and therefore not create an object. This ensures that all objects created are valid -- they contain valid data. We have not yet learned about throwing exceptions. We may do this as a lab excercise later.)

 

TURNING IN YOUR PROGRAM: You will turn in two files. You'll have the driver program and your Item file. Submit both files to neelix in the appropriate folder.