CIS 67: Homework 13
Handed out: 04/17/07
Due: by 10:00pm on 04/30/07
Email program to TA
CIS67: Homework 13
This homework, our last, is an extension of what we did in homework 12.
The extensions are in three directions:
- Instead of a repository of only CDs,
we will build a repository of information about CDs, DVDs, and games.
Here are the attributes of a CD: uniqueId, title, artist, cost, haveIt, comment.
Here are the attributes of a DVD: uniqueId, title, director, date, cost, haveIt, comment.
Here are the attributes of a game: uniqueId, title, publisher, numberOfPlayers, date, cost, haveIt,
comment. As you see CDs, DVDs, and games have a lot of attributes in common, so it pays to define an
abstract class Item of which they are all subclasses.
- We will be more carefuly reading from a user the definition of an item, to make sure that
the values are reasonable (remember that we know how to deal with
exceptions and to write exception handlers).
- In addition to use text IO we will use object IO. A complete example
of object IO is
here
The information about CDs, DVDs, and games (for brevity, of items) is kept in a file.
The order of the items in the file is up to you.
A number of successive lines in the file are used to represent an item:
- uniqueId: The first two letters of the unique id will identify if the item is a CD (CD),
or a DVD (DV), or a game (GM).
- Then a series of lines also of the form attribute value.
An example of possible item file is
here.
Notice that comments are optional and that the information about an item is separated from the
information for the following item by an empty line.
Define classes to represent Item, CD, DVD, Game.
In addition to constructors, they should have access methods for each attribute
plus modifiers for each attribute except uniqueId.
It should have also methods for writing an item to a PrintWriter and for
reading it with/out prompt from a Scanner.
Your main program will assume that the information about items is in a file items.txt.
The items in main memory are kept in an itemList variable.
It should in a loop offer the following choices to the user:
- Create a new item entry.
/* The new item is added to itemList */
- Delete an existing item entry
/* The item is identified by its uniqueId and is removed, if there, from itemList */
- Update modifiable attributes of an item
/* The item is identified by its uniqueId */
- List items
/* The items in itemList are displayed to the user. */
- Import item data from a file.
/* The user is prompted for the name of the file. This name will be
without file extension (so a file fraction.txt or fraction.dat will be
called just fraction). Then if there is a readable binary file with
extension
"dat" it is selected, otherwise the text file with extension "txt" will be
chosen.
Then the content of the chosen file
is merged without duplication (two items are duplicates if with the same uniqueId)
with the itemList.*/
- Export item data to a file.
/* The user is prompted for the name of a file. Again the name of the file
will be without file extension.
Then everything is as in List items case
with the difference that now the items are sent both to a text file with
extension "txt" and to a binary file with extension "dat"
instead of being displayed. The
itemList variable is left unchanged.
- Terminate.
/* The content of itemList is saved to items-new.txt */
The program keeps in main memory the item information in an ArrayList, or in an array if you prefer,
or both. Searches are done using a form of binary search.
When the program terminates the current content is saved to the files
items-new.txt and items-new.dat.
Send to the TA
a case analysis for this problem: problem statement, analysis, design,
implementation, and testing.