MC28 Lab 7: CompuDuds in Java (Fall 1996)
Due: December 13, 1996
In this lab, you'll make a few minor alterations to a Java version of
the CompuDuds program from our textbook. The point is to become
familiar with the mechanics of Java. The program is divided into five
classes, each in its own file. The five files are
To make a copy of all the files, the simplest approach would be to
use the shell to copy the whole directory containing the files. If you
in a shell window type
- ItemList.java the class that
holds the Items the customer is ordering
- Item.java the base class for
different kinds of clothing items, specifically
- CompuDuds.java this is the main
program class; it has no instances but has a number of important ``static''
(i.e., class-wide, not associated with a specific instance) methods
cp -r ~max/www-docs/MC28/labs/lab7/code .
(note that this command ends with a space and then a period), you will
get a subdirectory called code containing all the files. Ask for help
with this if you need it.
To compile and run the program, you'll need to work in a shell
(terminal) window. First you'll need to change directory into the
directory where you have the files, e.g.
Then you need to execute a special command that makes the Java
compiler and execution system (``virtual machine'') available to you:
set path=(/usr/java/bin $path)
Now you can compile each of the files; for example, to compile
ItemList.java, you'd use the command
You need to do the corresponding command for each of the other four
files as well. The most important thing to remember is this: if you
make any change to any of the files, you must
recompile that particular file before you can test the program, and
you must save it out of the editor before you
recompile it. In other words, after making any change, you have to
save, then compile, then test. When you add a new class, it should go
in a file of its own, named after the class. You should then compile
that new file as well.
Once you have the five original files compiled, the first thing to do
is to test the program out without yet having made any changes. That
way you have a baseline for comparison: if it isn't working, you
aren't the one who broke it. To run the program, use the command
Now you can start making the necessary changes, and test and debug as
you go along. You are to do the following:
Course web site: http://www.gac.edu/~max/MC28
Modify the ItemList class so that it keeps a running total price as
Items are added and deleted, and simply returns that in the totalPrice
method, rather than adding up all the prices then. The program's
outward behavior should remain unchanged.
Add one or more new kinds of clothing, perhaps to suit your own tastes
Add the ability to mark down the price of an Item by 10%, and use it
to add the ability to mark down the price of all the Items in an
ItemList by 10%. Finally, add a new option to the CompuDuds user
interface that discounts everything that has been selected by 10%.
Warning: discounting each item by 10% and discounting the total price
by 10% may wind up with a total price that doesn't match the sum of the
individual prices, due to roundoff.
Instructor: Max Hailperin <firstname.lastname@example.org>
Lab instructor: David Wolfe <email@example.com>