Here's the instructions:
Write a Song class that contains the following properties along with appropriate get/set methods. Please note this is a pretty simple object and not anywhere near the level of completeness required for writing an actual music player program (especially since this program doesn't know how to read and play songs and there are no MP3 files involved!).
Name (String) - The name of the song
Artist (String) - The name of the band or artist
Album (String) - The album from which the song is from
Length (int) - The length of the song in milliseconds
Now write a class called Playlist that will manage your song objects. It should have the following properties.
Songs (an array of data type Song) - The size is hard-coded to 12. That's all the songs we have room for in our collection.
Count (int) - Keeps track of the total number of songs stored in the collection and also the next open position in the songs array.
Name - A string that holds the name of the playlist. This is incase you ever want to make multiple playlists. Some names for a playlist might be "Gym" or "Podcasts" but the user can enter anything they like here. You should write a getter/setter for this value.
It should have at least the following behaviors.
void add(Song a) - Adds a Song to the collection. If the collection is full it does nothing. This could print an error to the screen if you want it to. We'll cover exceptions later in the semester and you are not expected to use them here.
Song get(int i) - Returns the Song at the given index but doesn't remove it. You need to check the value of i to avoid accessing invalid array indices.
Song remove(String name) - Removes the first Song in the collection with the given name. If it does not find a Song with that name it returns null. Yes, this requires a linear search of the Songs array.
void print() - Prints a nicely formatted list of all the Songs in the collection.
int size() - Returns the total number of Songs in the collection.
int totalTime() - Returns the cumulative time of all the Songs in the playlist in milliseconds.
String formattedTotalTime() Returns the cumulative time of all the Songs in the playlist in the format hh:mm:ss as a String.
void clear() - Deletes all Songs from the collection.
Finally, write a driver class to test this out. Create a Playlist object and give it a name. Then, make a few Song objects and add them to your Playlist object. Print the collection, remove some Songs, and print the collection again. Do your best to demonstrate the full functionality of the program. This does not need to be an interactive driver. It's fine to hard-code this piece of the assignment.
Additional Notes When you remove a Song from the list you can't leave an empty spot in the array. How will you deal with this? DO NOT use an ArrayList to manage your Songs, you must use an array. DO NOT extend ArrayList for this assignment. We'll do that later ;-) You are free to write additional "helper" methods if you want to do so. The methods I've listed are the minimum requirements for the assignment. You are always free to add more if it helps. What to Submit Your .java files for the Song, Playlist, and Driver classes.
This is what I have so far, i'm kind of stuck on what to do next... I've put all the classes below.
All 2 RepliesReply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.