CS 1401 Assignment #8

Date Assigned: Tuesday, October 25, 2005 or Wednesday, October 26, 2005.

Due Date: correspondingly, Tuesday, November 1, 2005, or Wednesday, November 2, 2005, before the beginning of your lab section.

Goals: to learn how to use inheritance to design an application with derived classes.

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: When writing research papers, we need to put appropriate references to cite related work, to support our claims and to acknowledge other publications that helped in our research. References must be in a consistent style, and the computer can help in generating nice looking references. A typical way is to put the references in a file with tagged fields. The computer program then reads the fields and generates a formatted file with the appropriate style. An important advantage of this approach is that if we want to change the format of the references, we don't need to change all the references. We only modify the code that generates the formatted file. Your assignment is to design an application which reads references from an input file and generates an output file in html format, implementing some basic styling like bold and italics. Follow the steps below.

Step 1. Design a superclass Reference that can be extended to create the derived classes Book, Article and PhDThesis. All three kinds of references have an author, a title and a year, so create appropriate fields in the Reference class. In addition to the author and title, a book has the following required field: publisher. It also has the following optional fields: volume, address, edition. An article has the following required field: journal. It also has optional fields: volume, pages. A PhD thesis has the following required field: school. It also has optional field: address. Since we will not do any calculations on the year, it ok to use String for all fields. When an optional field is not used, it should be initialized to its default value, the empty string.

Step 2. Define constructor methods in both the superclass and the derived class.

Step 3. Define a toString method in the superclass and in each of the subclass. The format should be as follows. See the sample output for the expected result.

Whenever an optional field is not provided, skip that part in the produced string.

Step 4. Write an application ReferenceApp. Prompt the user for a file name to read in the references. Also prompt the user for an output file name. Open the input file for reading and the output file for writing. Write the two header lines into the output file (see sample). Then, for each reference in the input file, instantiate an object with the proper initialization. The input file will contain a number of references separated by blank lines. Each reference will have the first line with a keyword "book", "article" or "phdthesis". Then for each of the fields, not necessarily in order, it will have a keyword with the name of the field followed by a line with the contents of the field. See the sample input file for an example. While error checking is important, we will see this topic in more details in Chapter 9. So for now, you can assume that the input file has the correct format. Then use the toString method of the object to generate a string to write on the output file. Follow each entry with "<", "p" and ">", which indicates a new paragraph in html. Italic is done by putting "<", "i" and ">" before the italic text and "<", "/i" and ">" after. Bold is similar, but with "b" instead of "i".

Step 5. Create a test input file. Your test input file should contain different cases, so as to test the different possibilities for optional fields. Also, put (for fun) an entry with the Ph. D. thesis that you would like to write.

Deliverables: as announced in the labs.