Revising the Music Archive Program

Lab Assignment 5
to prepare for Lab Exam 5

This assignment gives further practice in code reuse, and has you apply simple abstract classes, abstract methods, inheritance and polymorphism to organize data.


Program requirements

Figures! Just as you get the music archive ordered-by-title report up and running, you’re informed that more information about each item in the archive is going to be collected, that it is going to vary depending upon the type of music item, and that it is to appear, labeled and nicely formatted, as part of the report. (By the way, this changing of specifications while a project is in development happens a lot in the world of programming.)

In particular,

As before, this revised program is to print out a report, in order by title, of all the music items, with all of one item’s information per line, but with labels as part of the printed text so that the reader can easily tell what information is what; as before, the line should also be easy to read and nicely formatted. For example, a line reading

R12129 Roger Miller Classics C 18 2002


is not very easy to understand (and what would not meet the requirements of this assignment). Writing out the line as, say,

Accession#: R12129 | Title: Roger Miller Classics | Media: C | # of Tracks: 18 | Yr. Released: 2002


does make it easy to tell what information is what (and does meet the requirements of this lab).

The program is also to print the same counts to the console window, following the same format requirements, as was done in Assignment 4.


Technical details

The input file given to you will still be a text file, called music.txt, with each item’s information on one line in the format described above. Each line will end, as before, with the standard PC end-of-line mark, a carriage return character followed by a line feed character.

Again, the music file will have been run though a testing program to ensure its format is correct and that its fields follow the specifications given for them. You can be confident that the music file will be in the correct format to be fed into your program. The MusicFile class has been revised so it properly processes the revised music file; it has the same routines as before. Again, the routines are documented, this time in the file MusicArchiveDoc.txt, which is provided to you in the Eclipse project for this assignment. The only difference is that MusicFile’s readItem() returns an ArrayList with as many cells as necessary to hold the item’s information, rather than always returning an ArrayList with three cells.

Music items, of course, still exist, and all music items still have an accession number, title, and media code. But now, items have additonal information that differs by the kind of media. To encapsulate this situation in a nice way, we still have the MusicItem class, which stores all information and methods that apply to all music types. Then, from MusicItem, we extended specialty classes, one for each media type, that contain (in addition to what is inherited from MusicItem) the fields and methods needed to store and manipulate the supplemental information particular to that kind of media. Read the comments in the MusicItem file for details on these extended classes.

Some of the supplemental information is conceptually numeric, for example, the number of tracks on a CD, but this information is encoded as a string in order for it to be placed in the music information String ArrayList. To obtain the numeric equivaluent of this encoded string, use the parseInt method, a static method in Integer that takes a string and returns its integer equivalent (or throws an exception if the string cannot be converted to an integer). For instance, to obtain the number of tracks on a CD from the music item's information array, you would say something like numberOfTracks = Integer.parseInt(item.get(NUMBER_OF_TRACKS_POSITION)).

The index is to be placed into a text file still called index.txt. It will have the information about each musical item on one line, nicely formatted, and be in alphabetical order by title. The IndexFile method writeItem() has been modified so it calls the method displaySupplementalInfo() , which returns a String of the supplemental data formatted for printing on the report; writeItem() plaes that information in the appropriate place on the report. The format of the supplemental information is up to you; make it easy to read.

As before, the details of writing to and formatting the lines of the index file have been encapsulated in the class IndexFile, which is being made available to you as a class file. Its public methods are also documented in MusicArchiveDoc.txt

The media category code constants are now in the MusicItem class.

All other aspects of the program are the same as before; all that changes is the input data and its appearance on the by-title report. So, the Bucket and MusicList classes can be used as is from the previous assignment, since they already meet this assignment’s requirements.. These two classes are provided to you as class files, and documented in MusicArchiveDoc.txt. Some methods in MusicItem and MusicManager also can be left unchanged from the previous assignment, since they are not affected by the presence of additional music information; feel free to reuse that code from Lab Assignment 4.

Archive personnel are still compiling the revised list of music, so you will have to test your program using test files. We’ve provided one for you, again called music.txt; it, too, is in the project file for this assignment. You should also test your program on other test lists you put together, in the manner described in the previous assignment.

The files discussed above, along with, as usual, a number of Java skeleton programs, are in the zipped Eclipse project file 21Lab5.zip. Using the same procedure that you followed previously, unzip the file and import this project into your Eclipse workspace. Do look over the provided code carefully to get a good feel for what the various classes accomplish, and particularly for how the various subclasses of MusicItem work together to deal with multiple media types.


About Lab Exam 5

Lab Exam 4 will be very similar, but perhaps not identical, to the program you have been asked to write for this assignment. The lab exam will ask you to complete one or more of the following methods:



Written by Norman Jacobson for ICS 21 Fall 2006, November 2006.
Minor edits for clarity, by Norman Jacobson, December 2006 and September 2008.
Edited for clarity and to reflect use of Eclipse, by Norman Jacobson, September 2009.
Minor typos fixed, by Norman Jacobson, September 2010.
Revised to require labeling of values in supplemental information string, and to change name
  of method doing so to reflect this requirement, by Norman Jacobson, December 2010.
Added text to explain need for, and use of, parseInt(), by Norman Jacobson, January, 2012.