Computer Science 261
Assignment # 7
Due:
- Part 1 will be due Monday, Oct. 29
- Part 2 will be due Thursday, Nov. 1
Purpose:
- To develop the second in a series of programs exploring data structures
that can be used to store a list of objects with a standard interface.
To learn the advantages and disadvantages of each approach. In the
course of the next several exercises in 'lists of objects', we will cover
- Storing objects in linked lists
- Storing objects in binary search trees
- (if time permits) Hash tables and indexes
- Please note that Java already contains built-in data structures to do all
this. Our purpose is to learn how they work so that we can make
informed choices about which one to use in a particular situation, and also
to be able to use them in programming languages that are not as rich in data
structures as is Java.
Part 1: Warm-up exercise:
Using either LinkedList.java or AnotherLinkedList.java (both in the handouts
folder), add a delete method and modify the main procedure to test the new
method with the others already present. Using the main method from
AnotherLinkedList.java will be a sufficient test. Retain the name for your
program (LinkedList.java or AnotherLinkedList).
Part 2: Linked lists for storing parts.
Write an LinkedInventoryObject class description for parts with the
following fields and methods:
- Fields
- Linked list of part objects maintained in order by part number.
- Any other fields you might find useful.
- Methods
- Constructor to create an empty part list.
- Other Methods
- print - prints a listing of all the parts in the inventory.
You can do this by using the PartObject's print method, or by
using the GetPartNumber, etc. commands to get the contents of
individual fields and generate a nicely formatted listing.
The list should be in ascending part number order. If it is
not, the sort routine (see below) should be called to sort the array.
- AddPart - accepts a part object as an argument, adds it to
the list. If the array is full, or if the part already exists, print a message and return doing
nothing. Important note: We will later want to throw an exception
in this sort of case. Please don't do this here - the test driver program
will not be written to catch exceptions.
- DeletePart - accepts a part number as an argument) and deletes the corresponding
object if it is in the inventory. If not in the inventory, print
a message and return doing nothing.
- FindPart - accepts a part number as an argument and returns the part
with that part number if found. Only a sequential search is
possible.
I will use the same main() program I used on the ArrayInventoryObject
(modified, of course, for a LinkedInventoryObject instead of an
ArrayInventoryObject).
Questions? Please ask!