CS21 Fall 2005
Homework 10: CD Database Take 2
Due: Monday, April 17 before 11:30 pm

You may work with a partner, and you should submit your solution as a single tar file (see the hw 8 assignment for info on using tar).

For this assignment, you will add two features to your homework 9 solution. Start by creating a hw10 subdirectory, then copy your hw09 solution to your hw10 directory, and then copy my hw10db.txt CD database file for testing purposes:

% cd cs21
% mkdir hw10
% cd hw10
% cp ../hw09/*.java .
% cp ../hw09/Makefile .
% cp ~newhall/public/cs21/hw10/hw10db.txt .

For this assignment, you will add two features to your homework 9 solution (the first is the most important one, so make sure you get it before moving on to the second feature):
  1. Sort the linked list of CDInfo that is read in from the database. Use insertion sort to sort elements as you read them in and as you add them to the LinkedList. And, add new CDs in sorted order to the LinkedList (menu option 5).

    To the CDInfo class add a compareTo method that compares to CDInfo object by:

    1. Their artist fields (use the String class' compareTo to compare String fields not the EqualIgnoringWhiteCase method that you will implement for the second part of this assignment)
    2. if these match, then compare CDInfo objects by their title fields
    3. if these match, then by their date fields

    For example, the following CDInfo objects:

        james Brown, Get on the Good Foot, 1972
        Charles Mingus, Mingus Ah Um, 1959 
        X, Under the Big Black Sun, 1982 
        X, More Fun in the New World, 1983
    
    are in this order when sorted:
        Charles Mingus, Mingus Ah Um, 1959 
        X, More Fun in the New World, 1983
        X, Under the Big Black Sun, 1982 
        james Brown, Get on the Good Foot, 1972
    
    (note: the ASCII ordering of characters means that strings that start with space or tab chars will come before any strings that start with alphabetic chars, and strings starting with upper-case chars will come before strings starting with lower-case chars)

  2. Add a static method, EqualIgnoringWhiteCase, to the CDInfo class. This method should take two Strings and return true if they are equal ignoring case and ignoring white space chars (tab chars '\t' and space chars ' '). For example, the following call evaluates to true:
    	EqualIgnoringWhiteCase("   hello      there    ",   "HELLO THERE")
    

    Next, change the methods in the CDInfo class used by menu options (1) and (2) to compare two CDInfo objects author and title fields so that they call your EqualIgnoringWhiteCase method instead of the String class' compareTo method. As a result, menu options (2) in the CDDMgr program should match a CDs entitled "Greatest Hits" and " greatest hits " to a query for all CDs entitled "greatest hits", for example. And, menu option (1) should work in a similar way.

    There is documentation on the String class on the Tues week 3 in-class assignment page.


Sample Output

Here is some sample output from my program:
% java CDDBMgr  hw10db.txt

There are 15 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

    patti      SMITH, Easter  , 1979
Bob Marley, Survival, 1979
Charles Mingus, Ah Um, 1959
De La Soul, 3 Feet High and Rising, 1989
Funkadelic, GREATEST HITS, 1978
James Brown,    greatest     hits   , 1990
James Brown, Get on the Good Foot, 1972
Patti Smith, Horses, 1975
Public Enemy, It Takes a Nation of Millions to Hold Us Back, 1988
Sleater-Kinney, Dig Me Out, 1997
Sly & the Family Stone, Fresh, 1973
Sly & the Family Stone, There's a Riot Goin' On, 1971
X, More Fun in the New World, 1983
X, Under the Big Black Sun, 1982
the specials, greatest hits, 1995
-----------------------------------------------
There are 15 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: patti SMITh
Albums by patti SMITh:
--------------------------------------------
    patti      SMITH, Easter  , 1979
Patti Smith, Horses, 1975
--------------------------------------------
There are 2 albums by patti SMITh

****  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:
--------------------------------------------
Funkadelic, GREATEST HITS, 1978
James Brown,    greatest     hits   , 1990
the specials, greatest hits, 1995
--------------------------------------------
There are 3 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: 5

Enter the artist's name: De La Soul
Enter the album title: de la soul is dead
Enter a release year: 1991

****  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

    patti      SMITH, Easter  , 1979
Bob Marley, Survival, 1979
Charles Mingus, Ah Um, 1959
De La Soul, 3 Feet High and Rising, 1989
De La Soul, de la soul is dead, 1991
Funkadelic, GREATEST HITS, 1978
James Brown,    greatest     hits   , 1990
James Brown, Get on the Good Foot, 1972
Patti Smith, Horses, 1975
Public Enemy, It Takes a Nation of Millions to Hold Us Back, 1988
Sleater-Kinney, Dig Me Out, 1997
Sly & the Family Stone, Fresh, 1973
Sly & the Family Stone, There's a Riot Goin' On, 1971
X, More Fun in the New World, 1983
X, Under the Big Black Sun, 1982
the specials, greatest hits, 1995
-----------------------------------------------
There are 16 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: 3

Enter a release year: 1979
CDs released in 1979:
--------------------------------------------
    patti      SMITH, Easter  , 1979
Bob Marley, Survival, 1979
--------------------------------------------
There are 2 CDs released in 1979

****  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