CS21 Spring 2006
Homework 9 CD Database using Linked Lists
Due: Wednesday April 12 before 11:30 pm

You may work with one partner on this assignment. If you do so, either you or your partner should submit your joint solution with both names in the first comment of each file (please do not both submit it). You will submit your solution as a single tar file of your submit subdirectory (see the hw 8 assignment for instructions on how to create a tar file).

Copy over my starting point code for this assignment into your hw09 subdirecatory:

# from your hw09 subdirectory:
cp ~newhall/public/cs21/hw09/* .

Assignment

For this assignment you are going to implement a database program for a CD collection. Your program will:
  1. Read in the CD databse from a file given as a command line argument to your program. You will create a LinkedList of CDInfo objects initialized to the date read from the file.

  2. Enter a loop, asking the user to perform one of the following options until s/he choses Quit:
    1. Find all CDs by a given artist (and print out the number of matches)
    2. Find all CDs with a given title (and print out the number of matches)
    3. Find all CDs release on a given year (and print out the number of matches)
    4. List all the CDs in the database
    5. Add a new CD to the database
    6. Quit

  3. Write the contents of the database to an output file before exiting the program. Name your ouptput file the name of the inputfile with the string "_new" concat'ed to the end.

As you read in information about the next CD from the input file, create a new CDInfo object, and insert it at the tail of the LinkedList so that the resulting list order matches the order of the CDs in the input file. Also, add new CDs to the end of the LinkedList. Look at the week11 in-class assignment for information on the Scanner class and some of the methods that may be useful for reading in the database from the input file. Also, the start of the method to write the resulting file on exit is implemented for you...you just need to complete it.

For each "Find" option read in the user's choice and search the LinkedList for all matches. Your code should call LinkedList methods that will return an answer LinkedList containing just the matching results (e.g. a LinkedList of all CDInfo objects with a matching author).

For this assignment, matches for artist name and title should be exact (we will change this in the next assignment). For example, the string "Greatest Hits" for a CD title will not match CDs titled "The Greatest Hits" or "greatest hits", and will only match those whose title is exactly "Greatest Hits".

Implement and test incrementally. First read in the database and create the LinkedList. Next, write a method to print out the contents of the LinkedList. Next, implement Add a new CD and test it. Next, implement find by year option and test it, and so on.

You may assume that if the user is prompted to enter an int s/he enters an int value, a String, a String value. However, don't assume that the int value or String value is in range or valid (you need to gracefully handle invalid input of the correct type but not correct value(s)).


Sample Output

This is output from three runs of my program (one with small.txt, one with small.txt_new (the output file from the first run), and one with the much larger database file musicdb.txt):
% java CDDBMgr small.txt

There are 11 CDS. 


****  MENU OPTIONS ****
	1) to see all works by a given artist
	2) to see all albums with a given title
	3) to see all albums released in a give year
	4) to see the complete list
	5) to add a new CD to the collection
	6) to quit
***********************
Enter your choice: 4

Public Enemy, It Takes a Nation of Millions to Hold Us Back, 1988
Sly & the Family Stone, Fresh, 1973
Bob Marley, Survival, 1979
X, Under the Big Black Sun, 1982
James Brown, Get on the Good Foot, 1972
Sly & the Family Stone, There's a Riot Goin' On, 1971
De La Soul, 3 Feet High and Rising, 1989
Patti Smith, Horses, 1975
Sleater-Kinney, Dig Me Out, 1997
Charles Mingus, Mingus Ah Um, 1959
X, More Fun in the New World, 1983
-----------------------------------------------
There are 11 CDs

****  MENU OPTIONS ****
	1) to see all works by a given artist
	2) to see all albums with a given title
	3) to see all albums released in a give year
	4) to see the complete list
	5) to add a new CD to the collection
	6) to quit
***********************
Enter your choice: 5

Enter the artist's name: John Coltrane
Enter the album title: Blue Train
Enter a release year: 1957

****  MENU OPTIONS ****
	1) to see all works by a given artist
	2) to see all albums with a given title
	3) to see all albums released in a give year
	4) to see the complete list
	5) to add a new CD to the collection
	6) to quit
***********************
Enter your choice: 4

Public Enemy, It Takes a Nation of Millions to Hold Us Back, 1988
Sly & the Family Stone, Fresh, 1973
Bob Marley, Survival, 1979
X, Under the Big Black Sun, 1982
James Brown, Get on the Good Foot, 1972
Sly & the Family Stone, There's a Riot Goin' On, 1971
De La Soul, 3 Feet High and Rising, 1989
Patti Smith, Horses, 1975
Sleater-Kinney, Dig Me Out, 1997
Charles Mingus, Mingus Ah Um, 1959
X, More Fun in the New World, 1983
John Coltrane, Blue Train, 1957
-----------------------------------------------
There are 12 CDs

****  MENU OPTIONS ****
	1) to see all works by a given artist
	2) to see all albums with a given title
	3) to see all albums released in a give year
	4) to see the complete list
	5) to add a new CD to the collection
	6) to quit
***********************
Enter your choice: 6

bye, bye


% java CDDBMgr small.txt_new

There are 12 CDS. 


****  MENU OPTIONS ****
	1) to see all works by a given artist
	2) to see all albums with a given title
	3) to see all albums released in a give year
	4) to see the complete list
	5) to add a new CD to the collection
	6) to quit
***********************
Enter your choice: 4

Public Enemy, It Takes a Nation of Millions to Hold Us Back, 1988
Sly & the Family Stone, Fresh, 1973
Bob Marley, Survival, 1979
X, Under the Big Black Sun, 1982
James Brown, Get on the Good Foot, 1972
Sly & the Family Stone, There's a Riot Goin' On, 1971
De La Soul, 3 Feet High and Rising, 1989
Patti Smith, Horses, 1975
Sleater-Kinney, Dig Me Out, 1997
Charles Mingus, Mingus Ah Um, 1959
X, More Fun in the New World, 1983
John Coltrane, Blue Train, 1957
-----------------------------------------------
There are 12 CDs

****  MENU OPTIONS ****
	1) to see all works by a given artist
	2) to see all albums with a given title
	3) to see all albums released in a give year
	4) to see the complete list
	5) to add a new CD to the collection
	6) to quit
***********************
Enter your choice: 1

Enter the name of the artist: X
Albums by X:
--------------------------------------------
X, Under the Big Black Sun, 1982
X, More Fun in the New World, 1983
--------------------------------------------
There are 2 albums by X

****  MENU OPTIONS ****
	1) to see all works by a given artist
	2) to see all albums with a given title
	3) to see all albums released in a give year
	4) to see the complete list
	5) to add a new CD to the collection
	6) to quit
***********************
Enter your choice: 6

bye, bye


% java CDDBMgr musicdb.txt 

There are 1155 CDS. 


****  MENU OPTIONS ****
	1) to see all works by a given artist
	2) to see all albums with a given title
	3) to see all albums released in a give year
	4) to see the complete list
	5) to add a new CD to the collection
	6) to quit
***********************
Enter your choice: 2

Enter a CD title: Greatest Hits
CDs named Greatest Hits:
--------------------------------------------
Fleetwood Mac, Greatest Hits, 1988
Journey, Greatest Hits, 1988
The Cars, Greatest Hits, 1985
Air Supply, Greatest Hits, 1984
--------------------------------------------
There are 4 CDs named Greatest Hits

****  MENU OPTIONS ****
	1) to see all works by a given artist
	2) to see all albums with a given title
	3) to see all albums released in a give year
	4) to see the complete list
	5) to add a new CD to the collection
	6) to quit
***********************
Enter your choice: 3

Enter a release year: 1970
CDs released in 1970:
--------------------------------------------
Simon and Garfunkel, Bridge Over Troubled Water, 1970
The Moody Blues, A Question Of Balance, 1970
Genesis, Trespass, 1970
Genesis, Genesis: Rare Tapes Volume 1, 1970
--------------------------------------------
There are 4 CDs released in 1970

****  MENU OPTIONS ****
	1) to see all works by a given artist
	2) to see all albums with a given title
	3) to see all albums released in a give year
	4) to see the complete list
	5) to add a new CD to the collection
	6) to quit
***********************
Enter your choice: 1

Enter the name of the artist: James Brown
Sorry, there are no albums by James Brown

****  MENU OPTIONS ****
	1) to see all works by a given artist
	2) to see all albums with a given title
	3) to see all albums released in a give year
	4) to see the complete list
	5) to add a new CD to the collection
	6) to quit
***********************
Enter your choice: 2

Enter a CD title: Wild Gift
Sorry, there are no CDs named Wild Gift

****  MENU OPTIONS ****
	1) to see all works by a given artist
	2) to see all albums with a given title
	3) to see all albums released in a give year
	4) to see the complete list
	5) to add a new CD to the collection
	6) to quit
***********************
Enter your choice: 3

Enter a release year: 1959
Sorry, there are no CDs released in  1959

****  MENU OPTIONS ****
	1) to see all works by a given artist
	2) to see all albums with a given title
	3) to see all albums released in a give year
	4) to see the complete list
	5) to add a new CD to the collection
	6) to quit
***********************
Enter your choice: 1

Enter the name of the artist: Yo La Tengo
Albums by Yo La Tengo:
--------------------------------------------
Yo La Tengo, Prisoners Of Love (Disc 1), 1997
Yo La Tengo, And Then Nothing Turned Itself Inside-Out, 2000
Yo La Tengo, Prisoners Of Love (Disc 2), 1995
Yo La Tengo, Prisoners Of Love (Disc 2), 1993
Yo La Tengo, Prisoners Of Love (Disc 2), 1991
Yo La Tengo, Prisoners Of Love (Disc 2), 1990
Yo La Tengo, Prisoners Of Love (Disc 1), 1995
Yo La Tengo, Prisoners Of Love (Disc 1), 1987
Yo La Tengo, Prisoners Of Love (Disc 2), 2003
Yo La Tengo, Prisoners Of Love (Disc 2), 1995
Yo La Tengo, Prisoners Of Love (Disc 2), 1989
Yo La Tengo, Prisoners Of Love (Disc 2), 1998
Yo La Tengo, Prisoners Of Love (Disc 2), 2000
Yo La Tengo, Prisoners Of Love (Disc 2), 2002
Yo La Tengo, Prisoners Of Love (Disc 1), 1989
Yo La Tengo, Prisoners Of Love (Disc 2), 1987
Yo La Tengo, Prisoners Of Love (Disc 2), 1985
Yo La Tengo, Prisoners Of Love (Disc 1), 1997
Yo La Tengo, Prisoners Of Love (Disc 1), 1991
Yo La Tengo, Electr-O-Pura, 1995
Yo La Tengo, Prisoners Of Love (Disc 1), 1993
Yo La Tengo, Prisoners Of Love (Disc 1), 1993
Yo La Tengo, Prisoners Of Love (Disc 1), 1990
Yo La Tengo, Prisoners Of Love (Disc 2), 1997
Yo La Tengo, Prisoners Of Love (Disc 1), 2000
Yo La Tengo, Prisoners Of Love (Disc 1), 2003
Yo La Tengo, Prisoners Of Love (Disc 1), 2000
--------------------------------------------
There are 27 albums by Yo La Tengo

****  MENU OPTIONS ****
	1) to see all works by a given artist
	2) to see all albums with a given title
	3) to see all albums released in a give year
	4) to see the complete list
	5) to add a new CD to the collection
	6) to quit
***********************
Enter your choice: 6

bye, bye