Project on Linked Lists: CD Library

Project - The Stamford CD Library Database Dates : 

Overview Note: you will undoubtedly need to have gone over Linked List background info in detail before doing this project.  Having reviewed and understood some existing Linked List example code will go a long way toward helping you see how to approach this project. If you do not understand linked lists prior to starting, you will not be able to do this project.

This project will have you write a program to be used by the Stamford Library to keep an online list of all the CD's in it's catalog. The program will present a menu to the user (the librarian) to enable him or her to add a CD title, delete a CD title, find a CD title, and list all the CD titles available. The record for a CD must contain:

  • The CD Album Title (string)
  • The CD Artist (string)
  • The number of tracks on the CD (int)
  • The Library tracking number for the CD (long int)
  • Number of copies that the library owns

  • There will be a number of things you'll need to have your program do, or not do:

  • It must present a menu to the user to choose from, as shown on the next slide.
  • If ADD is chosen, must ask for the five data items shown, and add the CD record to the list.

  • However:

  • Before adding a CD, must check to see if the library tracking number already exists in a record on the list. If it does, then the program must compare the new album title against the existing record. If they match, then it should just increment the number of copies field in the existing record by adding the number of new copies that the user has just entered to the value in the exisiting copies field. If the titles don't match, it should give the user an error message telling them that the tracking number is already in use, and NOT add the CD to the list and NOT increment anything.
  • If the tracking number does not exist on the list at all, then add the new record to the end of the list
  • Make sure that the tracking number, number of copies and number of tracks are all positive, non-zero integers.
  • If DELETE is chosen, ask the user for the tracking number to delete. If a record with that tracking number is found, then check its number of copies field. If that field equals 1, then delete the record from the list. If it is greater than one, then ask the user whether to delete only one copy, or to delete all copies of that album. If they choose all, then delete the entire record. If they choose one, then just decrement the number of copies field for that record by one.
  • If FIND is chosen, then ask the user whether to find by album title, or tracking number. Whichever they choose, then ask them either for the album title or the tracking number to look for. Search the linked list of records for that title or tracking number. If it is not found, then print a message to that effect, such as "A CD with tracking number 2494922 cannot be found". If it is found, then print out the information from the CD, as shown in the Operation section below.
  • If LIST is chosen, write a well-formatted report of all the CDs that are on the linked list to the console. In a real program, we might want to print this list sorted by artist, tracking number, etc., but for this program, you can just print the records in the order that they occur on the list.
  • If QUIT is chosen, print a nice "goodbye" message to the user, and quit the program. In a real program, you would want to "serialize" the records into a disk file or some other permanent storage, so that they could be read back in the next time you start the program. For now, we'll avoid storing the records and make the poor librarian retype all the CD records every morning when he opens the library and starts the program...

  • Design

    You should write a class called CDRecord that holds the five data items defined above, and a next reference so that it can be used in your linked list. This should be a well-designed class that protects it's data, has good defaults, etc.

    You should write a CDList class that models a linked list of CDRecord objects.

    You will write a CDLibrary class that contains the main method that should "drive" the program. It will have an "event loop" that will call methods as required on a CDLibrary object to ask the user for input, to process user input, etc. You will have one main function, and a number of other functions that should be used to perform various actions. The main program itself should be fairly short, and will probably have a while loop, with a switch statement inside to process the user's choices by calling functions. Do not make any method in CDLibrary other than the main method static unless you have a good design reason, and explain that reason in your method comments. (Generally try to avoid static methods as they are closely associated with procedural programming).

    Project Flow

    The decision flow starts in main, and flows to the right, depending on what the user chooses. After one of the logic paths is complete, control returns back to main, so the user can make another choice.

    Project Operation

    When you start the program, print out a nice welcome message, and then present the main menu to the user.  You should present the menu to the user after each command completes. The user should never have to guess, or remember all the commands because they have scrolled off the screen.

    You are not allowed to use any of the Java library data structure classes to implement the actual linked list, even if you've studied ahead and know how. You must implement your own linked list from scratch.

    a) Each operation on the linked list (ADD, DELETE, LIST, etc) must be defined within a separate method. You will probably need other "helper" functions as well.

    b) Your main program should be as small and as descriptive as possible. Functions should be reasonably small. Follow the guidance that "A function should do one thing, and do it well".

    c) You should trap basic NumberFormatExceptions, as well as other basic input exceptions so that the user cannot crash your program with a simple typo.

    d) You need to capture and deal with other types of bad input as well that don't cause exceptions. If the user enters a  command that you don't understand (e.g., ZDD instead of ADD), you should notify them, and continue. Do NOT quit the program on these types of errors.  You should print an informative error message (for the user) and continue.

    e) Comment your code!

    f) You MUST follow the order of input in the example above. If I enter "ADD" in your program, I expect to then enter a CD title, an artist name, etc, in that order. You should also duplicate the output as shown above as closely as possible.

    1 point
    I have completed the project(s) for this lesson and have demonstrated them to my instructor.