CISC370-010 Project 3


Assigned: June 20, 2001, Due: June 27, 2001
Reading and Writing our Animals
This project counts for 10% of the overall grade

Summary

In this project, we will be working with streams and files. We will use the code from Project 2 (recall the Animal class and its subclasses) to read and write our Animals from and to a file (a database of animals). In the end, we will have an interactive program that will prompt the user for selections to modify this Animal 'database' that we will create. Basic functions like Add, Delete, List and Select will be impelmented (also exit and re-write the database!).

Objective

The objectives of this project are to use streams in Java, including reading in info from standard input and reading/writing a binary database file. More practice with exception handling will also be done (as run time errors frequently happen when working with file I/O).

Reading/Writing our Animal objects to a file

The first step in this project is to go back and copy your classes from project 2 to a new directory so you can add some new methods to them. Namely, you will be implementing readAnimal() and writeAnimal() methods to read and write your animals from/to a file. This should be done by using the DataInputStream and DataOutputStream classes. The readAnimal() method in each class should take a FileInputStream object as a parameter and use methods such as readUTF(), readDouble(), etc. to instantiate a new object from a file. The writeAnimal() method in each class should take a FileOutputStream object as a parameter and use methods such as writeUTF(), writeDouble(), etc. to write out the object values to a file. Remember to practice good OOP techniques, including code re-use; meaning that you should be using the super class to take care of elements in it (as we did with the constructors and toString() in project 2). After this, you should write a small test program to write a few Animals to a file and then read them back in. Remember that we will have many different animals in one file (for our database), and that this will be a binary file, not text.

An Interactive Program

After getting your Animals to and from a file, now create an interactive program to do this for you. The program needs to accept one argument, a file name for the database. The program should first read information from the database (provided that it can, and if the file has the proper information!). Then the program should enter an interactive mode where you can enter information to the database. To be more specific, a sample running of the program to show the features required:
Sample Run
Here are the functions the program must do (Formally):

The Vector (or ArrayList) class should be used to implement a storage system in the program. The Vector will be the current working database until the program is exited and the user saves to the file.
NOTE: All data that is read from the keyboard must be checked- invalid input must be handled properly!!! So that we know what kind of object we about to read in, the first part of each record should be what type of animal the record is for (as a String, so use readUTF() to read that in).

Turn In:

Grading

  1. Animals to/from File (including exception handling) - 45%
  2. Interactive Program (including exception handling) - 45%
  3. JavaDoc on WebPage - 10%