CS 1401 Assignment #10
Date Assigned: Tuesday, November 8, 2005 or
Wednesday, November 9, 2005.
Due Date: correspondingly, Tuesday, November 15, 2005, or
Wednesday, November 16, 2005, before the beginning of
your lab section.
Goals: to learn how to include error-handling mechanisms in an
application.
Points:
This assignment is worth a total of 20 points. No late assignments
will be accepted, but credit will be given for partially completed
assignments turned in on time.
Assignment:
This assignment builds on your work on Assignment 8. In that assignment,
we assumed that the input file exists and that all the entries from the
input file have the required format.
Now that you are familiar with exceptions, modify your code in such
a way that your program will automatically take care of the following
exceptions (both pre-defined and user-defined):
- If the input file does not exist, your program should
print a a user-friendly error message to the screen, and ask the user
to re-enter the file name.
- If one of the records lacks a required field, your program
should:
- print the corresponding error message to the screen, and
- add, to the output file, a similar
error message instead of the value
of this field.
Example. If a record does not specify the author, as in:
book
title
Programming and Problem Solving with Java
year
2003
publisher
Jones and Bartlett
your program should do two things:
- First, it should send the message
Author not specified.
to the screen,
and
- Second, it should place the string AUTHOR NOT GIVEN in the
corresponding record in the output file, instead of the actual
author's names, so that the resulting record will look as follows:
AUTHOR NOT GIVEN, "Programming and Problem Solving with Java,"
Jones and Bartlett, 2003.
(So that the user will immediately see that something
is missing.)
Comment: in the input file, the fields do not necessarily
come in order: we can have author before title, or we can have title
before author.
For extra credit: make sure that your program recognizes
and takes appropriate care of the following three additional
types of errors:
- Type 1: extra field
- description: a record contains a field which is not one
of the required or optional ones;
- example: in addition to the year when the book
was published, there is also a month when it was published;
- how to handle this exception:
a reasonable idea is to inform the user about this extra field, and
to ignore it in the output file.
- Type 2: duplicate field
- Type 3: un-typed record
- description: a record does not have an indication of
whether it is a book
or an article or what;
- how to handle this exception: in some cases, we may
determine it from
the presence of auxiliary fields; in this case, we should handle
this record according to this type;
- example: the field "school" is
an indication that this is a PhD thesis, so if there is such a
field, we should treat this record as a PhD thesis.
Deliverables: as announced in the labs.