15-121 Homework 7: Maps & Music - Due 12/1 at midnight
Download and unzip hw7-code.zip, which contains
all the files you will need for this assignment. You will be writing code in
a number of files, including creating one class from the ground up.
The goals of this assignment are:
- to give you practice with the data structures we have seen this semester
- to deal with a fairly unstructured problem specification
- to build a complete solution from scratch leveraging the power of the Java API
Note: You will be graded in part on your coding style. Your code
should be easy to read, well organized, and concise. You should avoid
Background: The Assignment
This assignment is designed to mimic a simple music library and exercise the
data structures we have seen so far in so doing. You are given a plain text
file of songs, tunes.txt, (culled from a random professor's library).
Each song entry in the file is formatted in the following manner:
- genre (1 word), followed by any playlists the song is contained in (could
be 0), each separated by a semi-colon (;) (every song belongs
to exactly one genre, but can belong to zero, one, or more playlists)
- a blank line to separate entries (warning: there is no
blank line after the last entry!)
Your job is to read the data file into a collection of your choosing (e.g.,
an ArrayList) and provide the following commands/funtionality in
the MusicLibrary.java file:
- display all songs (this should include all the information for each song:
its title, artist, album, and genre)
- display all artists (this should display a list of unique artists)
- given an artist, display all the songs by that artist
- display all genres
- given a genre, display all the songs in that genre
- display all playlists
- given a playlist, display all the songs in that playlist
- add a new song with all relevant information (artist, title, album,
genre, playlist(s)), or an appropriate "already exists" error message
- create a new playlist (or an appropriate "already exists" error message)
- add a song to a particular playlist (with appropriate "not found" messages)
- write an updated version of the file, tunes.txt, preserving any
additions or changes made during the execution of the program (the
file must be written such that it can be read back in a
subsequent execution of the program!)
- quit the program - if the song library has been changed, but the updated
library has not been written back to the tunes.txt file, the user should
be told and given the option of writing the updated file before quitting
As in GradeBook and AnagramTree, you will need to build an
initial data structure to store all the songs. This collection will be
instantiated and built in the MusicLibrary constructor. I suggest
storing each song in the collection data structure and building the
appropriate initial map(s) as you read in each song, similar
to AnagramTree. If it isn't obvious, you will need to create a
simple Song class (name it what you will) and provide an appropriate
constructor and getter methods. The GradeBook homework should be
helpful to get an idea of what you'll need to do here.
Please make sure that you have a good, clean, modular design to your program.
Your main method (really any method) should not run
on for pages! Each command should dispatch a separate method to handle the
implementation of that command (at minimum!).
I suggest that you take a look at the files from the GradeBook
homework to get an idea of how to start to segment the work and provide the
user with a menu of choices and then dispatch those choices to the appropriate
For each command the user enters, if there is a parameter required,
e.g., displaySongsByArtist(), the user must be prompted for that input
and it must be used in the method. This is best done inside the method, not
as a parameter to the method.
The Data Structures
You may choose any data structure you wish to store the data from the file.
However, you must use at least one Map (TreeMap/HashMap) to capture
one of the associations. The most likely candidate for a Map is the
association between genres and songs.
BONUS (10 points)
I have included two sample Scanner files in the zip file for this homework.
One takes a URL and returns the HTML from the page the URL directs to. The
other returns the "plain text" from the page the URL directs to. You can earn
10 bonus points by implementing a feature that allows the user to see the
lyrics for a song that they desire. Again, how you choose to implement this
is totally up to you.
Note: you should only attempt the bonus once you have all the other
methods working correctly!
Submitting Your Work
When you have completed the assignment and tested your code thoroughly,
create a .zip file with your work. Name the zip file "your-andrew-id".zip and
email it to me at mjs @ cmu.edu.
Make sure to keep a copy of your work just in case!