define a new class, called MP3_Player, that manages a collection of Song objects
ID: 3657380 • Letter: D
Question
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.Explanation / Answer
public class Song { private String title; private String artist; private float duration; private float currentPlayPosition; private boolean IsPlaying; private float fileSize; public Song() { title = "no title"; artist = "no artist"; duration = 0.0f; currentPlayPosition = 0.0f; IsPlaying = false; fileSize = 0.0f; System.out.println("Constructor is finished"); } public Song(String t, String a, float d, float e) { title = t; artist = a; duration = d; fileSize = e; currentPlayPosition = 0.0f; IsPlaying = false; System.out.println("Constructor with parameters is finished"); } public String toString() { return "'" + title + "' by " + artist + " lasts for " + duration +" and is " +fileSize + "Mb large."; } public String getTitle() { return title; } public String getArtist() { return artist; } public float getDuration() { return duration; } public boolean getIsPlaying() { return IsPlaying; } public float getfileSize() { return fileSize; } public void setTitle(String newTitle) { if (newTitle.compareTo("") != 0) title = newTitle; } public void setArtist(String newArtist) { if (newArtist.compareTo("") != 0) artist = newArtist; } public void setDuration(float newDuration) { if(newDuration>=0) duration = newDuration; } public void setfileSize(float newSize) { if(newSize>=0) fileSize = newSize; } public void Play() { IsPlaying = true; currentPlayPosition += 0.1f; if(currentPlayPositionRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.