CS 163-01 Programming Assignment #2: Catalog
Due Wednesday, January 28, by 2 p.m.
-
Do this work individually, not in
teams.
Write a program for managing a catalog of two different kinds of
items: DVDs, and books.
This program does not need to take any command-line arguments,
but it should
repeatedly prompt the user for a command —
a single letter suffices —
and then do the commanded
operation, as follows:
- display items sorted by titles
- display items sorted by prices
- quit
- read list of items from file -- need to get name of file
from user
- store list of items into file -- need to get name of file
from user
Details of requirements for your work for this assignment are as follows:
- Represent DVDs as objects with attributes
title, minutes, and cents.
- Represent books as objects with attributes
title, authors, pages, and cents.
-
DVD and Book
should each be a subclass of a class say Item.
-
The common attributes title and cents probably should be
in
Item.
Then,
class Item should have methods
getTitle()
and
getPrice().
- Class
Item should have an `abstract' method
toString().
Classes DVD and Book
should have
implementations of this method.
- Use
String
as the return-type for
getTitle() .
-
As Java does with basic API classes,
it'll probably be useful to include the class name in
the
String produced by toString().
One thing this will facilitate is reading the list of items
from a file.
- Use an array to represent the list of items.
You may assume that
the list will not contain more than 128 items.
- For the commands "t" and "p", really do sort the array.
- Do the usual error-checking when accessing files.
- Delete dynamically allocated objects when the program finishes
using them.
You'll need to prepare a file
with a list of items in it.
For your submission,
provide a printout of your code
and
a printout of a
demonstrattion of your program.
For a 'grade' better than a "B",
use good style.
For even better grades,
use good style
and
implement further operations such as enabling
the user to add new items to the list,
change prices, etc.
(Copyright © 2009 by
Hugh McGuire
--
for thoughts about this, see:
http://www.cs.ucsb.edu/~mcguire/teaching/copyright_thoughts.html )