CSE331 Autumn 2011
Software Design and Implementation


Assignment 1 (10%): Due 11:59PM Friday October 7, 2011

This assignment is intended to review more Java (multi-class object-oriented programs, collections, etc.) and specifications and to start with some testing.

You will write the real meat (or if you prefer, tofu) for a basic shopping program for which we provide the GUI.  The program displays a catalog of items for sale (see image on the rights).  The program allows a user to purchase one or more items.   Some items have a discount when you buy enough of them.  In addition, if the user selects the checkbox at the bottom, the total will reflect a 10% discount if the cart contains at least a (fixed) minimum total of items (20 in the image and for the assignment). 

You will implement the following classes, which are specified below:

Item            a single item that can be purchased

DiscountedItem  a single item with a bulk discount for high-quantity purchases

Catalog            a set of all items that are available in the store

Purchase        a single item to be purchased in a given quantity

ShoppingCart    the list of all purchases that the user currently wants to make

ShopTest         a testing program to verify the functionality of the other classes

The specifications for these classes (except ShopTest) are here.

You need to download the support files ShoppingGui.java, ShoppingMain.java, and catalog.txt into your project to run the GUI.  The Java files need to go in the src folder for your project. Input files—in this case, catalog.txt—are placed in your project's root folder, the parent of its src or bin or lib or doc sub-folders.

Run ShoppingMain to launch the program. 

Assignment GUI screenshot

It's important to test your code incrementally as you are writing it. ShopTest is the class that will contain tests for your other classes. The GUI does not call every method of every class nor does it call them with all parameter values or in varied orders. You should test your code more aggressively than the GUI uses it, test more varied behavior. (Remember: the implementation should not focus on a particular client.) Use JUnit for your testing code. You can download and run a sample solution (you will likely not get another sample solution during 331) to get a feel for the behavior. (No, the source code is not included, only an executable of the sample solution.) But the specifications are the one and only precise definition of the assignment, so focus far more heavily on them.

Grading. 75% of your grade will be for program correctness. Correctness has two components: (a) does the GUI run properly (½ of correctness), and (b) is your implementation correct independent of the GUI (the other ½ of correctness). Note that this second part, especially, focuses on the quality of your test code. The remaining 25% is for documentation, code quality and style.

Documentation, code quality and style.

Use the @name tag to identify yourself (identify the assignment, the course, and your section) at the beginning of each class; make sure to include a general descriptive comment for each class, as well as for other key and complex sections of your code. You should focus carefully on using Javadoc tags, including the common standard ones such as @param, @return, and @throws as well as the CSE331-specific tags @requires, @modifies, and @effects.

Some Eclipse things you need to do

With just a little bit of luck, you should now be able to open build.xml, right-click in that window, and select Run As... >> Ant Build ... You will then see a window that is a bit of a mess with a large number of Ant targets. For now, the only one of interest is doc (which you'll need to scroll down to get most likely), which will now generate Javadoc for your own code using the 331 additional tags. (OK, you will get an error for one of them with the build -- I have to track down the code for derivedfield, which you don't need now anyway.) You can compile and run your program directly, without Ant.

Turn-in Instructions

Submit files to the course dropbox. Please do not archive files; upload them all individually to the dropbox.

You will need to turn in two kinds of files:

  1. Source code: the source code for the 6 classes listed above, plus any additional JUnit test classes you may have written. (You can have as many test classes as you want, but all tests must be invoked by running ShopTest.)
  2. Documentation: the 5 Javadoc files in the doc/a1 folder corresponding to each of the 5 non-test classes you implemented (Item.html, Catalog.html, etc.). You don't need to turn in the Javadoc for ShoppingMain and ShoppingGui, and you shouldn't write Javadoc for your test classes (but you should still write basic comments describing each method).