Java - MP3Player Solution
Write a program that simulates an MP3 player.
Your program should begin by using the Song class already developed in the tutorials. Modify this class to include another attribute, fileSize, that determines how much bytes of storage space the song uses. Add an accessor GetFileSize method and modify the constructor of the Song class to properly make use of this new attribute.
Next, you must define a new class, called MP3_Player, that manages a collection of Song objects. Since you don't know how many songs your player has, you should utilize the ArrayList to manage the songs. Additionally, your MP3_Player should have a storage capacity attribute which represents how much memory/storage the player holds. Your MP3_Player class must allow songs to be added, removed, and played. When a song is added, you should check to ensure that there is enough space remaining in the memory/storage of the MP3_Player; if the file size of the to-be-added song exceeds the remaining space of the player, the song should not be added. When a song is played, it should play the song completely by invoking the Play() method of the song until it is completed. When a song is removed, it should be taken out of the MP3_Player ArrayList that holds the songs. The MP3_Player should be able to display the list of songs it holds and display how much memory capacity it has and how much memory remains (based upon the songs' file sizes consuming some memory). Your class must conform to the following API:
void AddSong(Song) - takes in a Song to add if enough memory remains; if it cannot be added, display an error
void RemoveSong(Song) - takes in a Song to remove (if a match is found); if it cannot be removed, display an error
void PlaySong(int) - takes in an int and plays that song (by position); if this int exceeds the song count, display an error
int FreeSpace() - returns the amount of memory remaining in the player (capacity - the size consumed by songs)
int GetStorageCapacity() - returns how much memory the player has total (not considering how much is used)
MP3_Player() - the default constructor
MP3_Player(int) - the constructor that initializes the object's capacity based upon the int taken in
string toString() - returns the string representation of the object, including capacity and a list of songs in the MP3 player
Once you have defined these classes, write a main program that instantiates an object of the MP3_Player class and makes use of it, adding songs and displaying information concerning the object.
Be sure to comment your program well.
A sample output of a possible solution:
Justice for All added to the MP3 player.
Wish you were here added to the MP3 player.
You Belong With Me added to the MP3 player.
Cannot add 'Sabotage'; not enough free