15-100: Introductory/Intermediate Programming (Section F)
Fall 2006
Exercise
EC-music
Music
Due:  Friday, December 15
5pm

Assignment:  (This assignment is EXTRA CREDIT.)

Get the EC-music.zip file.   This contains the data files.

For this assignment, you are given a fairly hefty assignment and almost no framework.  Thus, you will be asked to do a lot more design than you are used to.  At the bottom of this, you will find some thoughts/suggestions on how to proceed.

You are to consider files that represent the tracks on a CD.  The format is as follows:
Line 1:  Name of CD
Line 2:  # of tracks
Subsequent lines:  the names of the tracks, one per line
Further, you have files that contain lists of CDs in a library.  The format is as follows:
Each CD is represented on two lines.  Line 1:  the name of the CD   Line 2:  the name of the file that contains the track listing
Note:  There is no number at the beginning of the file telling how many CDs are listed in the file.
Many sample CD files are given to you (and feel free to create you own).  Sample library files include library1.txt, library2.txt and library3.txt.

Your task:
  • Ask the user for a library file.
  • Read all CD information from this library into your program.
  • Ask the user whether they want "straight" play, "random" play, or sorted play.   There should then be a listing of songs from the library.
    • For all options, each song should be reported as: Song Title / name of CD  For example:
      • Jingle Bells / CS Choir Sings Overexposed Holiday Songs
      • Silent Night / CS Choir Sings Overexposed Holiday Songs
      • Hotel California / Eagles
      • Lyin' Eyes / Eagles
    • If they choose "straight", give a listing of all songs, in track order, one CD after another.   Each song on a CD should be listed  before songs from the next CD are listed.
    • If they choose "random", you must then ask them if they want "by CD" random or "total" random.
      • If they choose "by CD" random, the listing should include all songs on one CD in a random order before the songs from the next CD.
      • If they choose "total" random, then all of the songs from all CDs should be jumbled up in the listing.  
      • In either "random" option.  There should be no duplicates.  Partial credit if you get the rest working, but there are duplicates.  Extra credit if you ask the user whether or not to allow duplicates and act as appropriate.
    • If they choose "sorted" play, all songs in the library should be displayed in alphabetical order.
    • MORE Extra Credit:   Ask the user for only 6 CDs from the library to be included in the listing.  How the user specifies which 6 is up to you.

Suggestions on approach:

You will want to build a class to model the items you are dealing with.   A class to represent one CD seems reasonable.  A class to represent the entire library seems reasonable.   A class to represent a song list might be helpful as well. 

What would the CD class look like?  I suspect it will have fields for all of the information that you know about a CD.  (The tracks are likely to be an array.)   You will probably have accessor methods to get those individual pieces of information.    What would an accessor for a particular track look like?   Perhaps a method  public String getTrack(int n)   where n is the track number you want.  What mutators would you want?  Perhaps one to add a track to the end of the listing.  


What would the CDLibrary class look like?   
You are likely to have an array of CDs.   You will probably want a method to add a CD to the library.   You might want a method "getSongList" that returns a SongList meeting the specifications given.


What would the SongList class look like?   It will likely have an array of Strings.    You will want to be able to display the entire song list, as well as add a new song to it.  For instance, for "Random", you might start with an empty SongList, randomly select a song and add it to the list.

What would you have in your main method?   You will need to get the initial library file from the user and what they want to do with it.  Other than interactions with the user and with the files, there should be very little in main.


Handin:
  • Be sure to read the general handin instructions on the exercises page.
  • Rename the folder containing all of the files to be "lastname-firstname-100SectionLetter-music".   For example, if I were in Section Z, I would rename my folder to be:  "McElfresh-Scott-100Z-music"  (without the quotes).   
  • Create a zip file of this folder, with the same name as the folder (except with the .zip ending this time). Instructions for zipping can be found in the system and software handouts linked on the main course page.
  • Submit this file via the electronic handin.  If you have problems, contact me.