15-121 Homework 7: Maps & Music - Due 4/30 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
duplicate code.
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:
- artist
- title
- album
- 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!)
The Methods
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, album, artist, and genre)
- display all artists (this should display a list of unique artists)
- given an artist, display all the songs (title & album) by that artist
- display all genres
- given a genre, display all the songs (title & artist) in that genre
- display all playlists
- given a playlist, display all the songs (title & artist) 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.
Style
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!).
The UI
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
methods.
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 a Map (either a TreeMap or HashMap) to capture
the association between genres and songs. You may also find other
maps (like a playListMap) useful, but you only have to use
the one for genres.
BONUS (5 points)
You can earn 5 bonus points by implementing a feature that allows the user to
see the lyrics for a song that they desire. How you choose to implement this
is totally up to you, but you must abide by the following guidelines:
- you cannot ask the user for anything other than the song title and artist
(in particular, you cannot ask the user to provide a URL!)
- you must only print the lyrics, i.e., you should print no other extraneous
information/text from whatever website you use to find the lyrics
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
upload it to the HW7 folder on Box.
Make sure to keep a copy of your work just in case!