CCSU Fall 1998 Project 2 Posting Date: September 30, 1998 Due Date: October 14, 1998 Files Involved: (1) This file, the project description, which you are to download. (2) MailListSort.java, a program to bubble sort records in a mailing list, which you are to download and modify. (3) mlist.dat, a file containing data for a mailing list, which you are to create. (4) mlist.srt, a file containing the sorted mailing list, which your program is to create when it runs. Files (1) and (2) are available from the CS 152 Projects Web page. Relevant Demos: Demo 3 (CharIO.java), Demo 4 (RecordAccess.java), Demo 5 (SimpleBubSort.java), and all five parts of Demo 6 (An Interface and Object Sorting Method Demo). This project comes in only one part. It covers material on bubble sorting, file IO, records, and nested records. Background: The purpose of this project is to give you experience with a realistic programming problem. It often happens in the real world that an existing program must be modified in a very specific way. Project 2 asks you to do just this. The project will also give you (more) practice with files, arrays, nested records, and sorting. Description: MailListSort.java (available from the CS 152 Projects Web page) is a program to bubble sort records in a mailing list. MailListSort.java is defective in four important ways, and you are to download it and modify it to correct these deficiencies: First, MailListSort.java was originally written years ago for a version of Pascal which ran in batch mode under JCL on an IBM 370. MailListSort.java is a close to literal translation of the old Pascal program into Java. MailListSort.java doesn't run, because the javac compiler has no idea what to do with the $DATA statement (a holdover from a batch processing system on an IBM 370) at the end of the program. You are to modify MailListSort.java so it runs, and you are to place the list of records following the $DATA statement in a data file called mlist.dat. The file mlist.dat will contain the mailing list you will use for data when you test your program. Your program should write its sorted mailing list to a file. You will use the file named mlist.srt (stands for mailing list sorted) for output when you test your program. However, your program should take the file names of its input and output files from the command line, as MailListSort.java does, so a user could sort any file and store the output in any other file. When you test your program, you will type java MailListSort mlist.dat mlist.srt to read the records in from mlist.dat and write the sorted list of records out to mlist.srt. Second, the Member class in MailListSort.java does not use NESTED records. You are to modify class Member so it is a NESTED record type. Specifically, you are to declare two classes, Name and Address, which will contain, respectively, the name and the address of a member. (For class Name, you may simply use Demo 6c, Name.java. Hint: Simply download it, don't type it in.) Then you are revise class Member so it consists of a name and an address. You are to revise ALL methods in class Member so they call the corresponding methods from classes Name and Address. (For example, you will note that the readMember method is nicely commented so one block reads in a name and the second block reads in an address. Modify readMember so it calls readName to read in a name and readAddress to read in an address.) Test your program again to make sure it runs. Third, the Name, Address and Member classes should all be in separate files, rather than in the MailListSort.java file. Make this change. Test your program again to make sure it runs. The three modifications mentioned so far are fairly trivial, but the fourth one is more interesting. MailListSort.java, together with its accompanying classes Name, Address and Member, sorts a mailing list alphabetically by name, but the post office requires letters to be sorted by zip code first in bulk mailings. By ADDING or changing NO MORE THAN 4 LINES (not counting remarks and adding or changing modifiers like public and private), modify class MailListSort and/OR its accompanying classes Name, Address and Member, so it sorts the mailing list first by zip code, then by name, and finally by address. (Hint: Stare hard at the bubSort method in class ObjectBubSort and the gt method in class Member. DO NOT CHANGE class ObjectBubSort in ANY WAY.) Fourth, the writeName, writeAddress and writeMember methods print Member records with each field on a separate line. This result is unacceptable for addressing envelopes. You are to modify the above methods so Member records are printed out in a form suitable for addressing, somewhat like this: MICKEY D. MOUSE 133 INTERNATIONAL DISNEYLAND, CALIFORNIA 98210 Finally, BE SURE THE REMARKS in your program(s) are updated. Run and test your program again, with input file mlist.dat, and output file mlist.srt. General Instructions: (1) DO NOT HAND IN intermediate results. ONLY HAND IN the FINAL VERSION of your classes. (2) Hand in a FOLDER containing (1) printed copies of the text of the Name, Address, Member and MailListSort classes, (2) printed copies of your data and output files, and (3) a 3.5" floppy disk with the .java and .class files for your classes, and the data and output files for your program. The folder should have a pocket, as described in project 1. (3) Be sure to include both .java and .class files for interface LinearlyOrdered and class ObjectBubSort on your floppy disk, so I can easily re-compile your program. (4) Your .java and .class files MUST be named Name.java, Name.class, Address.java, Address.class, Member.java, Member.class, MailListSort.java and MailListSort.class, so I can easily find them. Your data file MUST be named mlist.dat, and your output file must be named mlist.srt (5) Each of your programs must begin with a remark box, as described in project 1. Under files, list mlist.dat and mlist.srt. (6) Each method in your program must begin with a remark box as described in project 1. (7) Your program MAY NOT use a depreciated api, as described in project 1.