Assignment #7
Due: Friday, October 29, 3:00PM,
-
The program you will write for this homework assignment allows a
company to maintain a database of customers and their contact information
in order to harrass them with junk mail and tele-marketing.
Here is a sketch of the design:
- class Name holds a first, last and middle names
for the customer (all of type String). It may be the case that only two names
are entered for a particular individual in which case the middle name/initial is null.
- class Address will hold the address for the costomer.
This should have fields to hold street address, suite or apartment number,
city, state and zip code. All these fields can be stored as
strings.
- class Phone will hold the phone number for a customer
with area code in a separate field.
- class ContactInfo will hold the information
(address and phone) for a customer.
- class DictionaryList<K extends Comparable, V> will be your
data structure that contains the set of Customers.
The "List" in the class name indicates that we are using a linked list for the
implementation. You can use the interface Comparable in the Java API or provide
your own. The important thing is that it has a
compareTo
method which allows you to give a linear ordering on the instances of the class.
In this case, the ordering should be based on the alphabetical ordering of the last name.
If these are the same, ties are broken by the first and then middle name.
You will implement DictionaryList as a generic class that could be used to store any set of
key and value pairs.
In this particular case, your data structure will hold pairs of names and
contact information.
Note that it is perfectly OK to have more than one customer with a given name.
We will be experimenting in
the future labs with
different data structures which will implement the necessary operations
on this set,
so your code should be written in such a way that you can change implementations
by changing only the line of code which instantiates the object which maintains the set.
To enforce that the interface to all the different implementations is uniform,
you should define an interface Dictionary which declares all the
operations on the set that you will need.
The actual data structures which you
write should implement Dictionary .
To make sure that the data structures are interchangeable, your program
should only have a reference to an instance of class Dictionary .
For now, you will only need to write one implentation of Dictionary which
holds the set of customers in an sorted linked list.
- Use good class design, making data members private and defining access
functions for member variables and other appropriate methods for
each object as needed.
- The GUI.
- You get to design this one.
- Include at least the following operations:
- load from named file. This should read in a group of customers
from the file and insert each one into the database. The format which you use to
read the input file should match the format in sample.txt given
below. Note that in the line after the address indicates that there
is no apartment or suite number. The city and state are on the
same line, separated by a comma.
- save to named file. This should format the information for each
customer nicely and print it out to an ASCII file. They can
be printed out in an arbitrary order. This will require and
iterator()
method in your Dictionary. This should be kept completely generic so that
your program only stores a reference to an instance of Iterator. When you
change Dictionary implementations, you will be using different implementations for Iterator
without changing any of the code in your program.
- use the graphical user interface to type in the name of a new customer along with their address and phone
and add that person to the database.
- lookup (and display) named customer's information. You will need to iterate through
names if there is more than one customer with a given name.
.
- change the contact information of a customer
-
Make sure to handle all unexpected events
gracefully using exception handling
where appropriate.
Although you can have customers with the same name, you should check that
they have different addresses. If the user does input two customers with
all information identical, you should throw an exception. Note that I have
not indicated what to do with every type of unexpected event. For example,
what if the user types in four names (i.e. they have two middle names)?
In these cases, use your judgement, do something sensible and document
the choice you made in your code. Of course, if there is something you feel
is an important design choice, you can ask me how to handle that situtaion.
-
Here is the sample input file: