Question
JAVA: The following methods need to be implemeneted: booleanadd(E element) void expandCapacity() ArrayList createSmartPlayList(Esong) ________________________________________________________ public class Playlist implements PlaylistADT { private E[] playlist; private
JAVA: The following methods need to be implemeneted:
booleanadd(E element)
void expandCapacity()
ArrayList
________________________________________________________
public class Playlist
public Playlist() { this.playlist = (E[]) new Object[DEFAULT_CAPACITY]; size = 0; }
@Override public boolean add(E element)
/** * Adds a song to the general playlist array - we don't care if a song is * added more than once. * @return boolean true/false if the song was added * @precondition element is not null * @precondition size is not at max capacity. * @param element the song to be added. * * 1. if the element is null, return false * 2. if the size of the Array is at its maximum, call expandCapacity. * 3. add the song to the playlist array. * 4. increment size counter. * 5. return true */
{ //if the playlist array is empty, we can't remove anything, return false if (this.isEmpty()) { return false; } if (DEFAULT_CAPACITY /** * Copies and doubles the size of the playlist array. */ private void expandCapacity() { throw new UnsupportedOperationException("Not supported yet."); } @Override public ArrayList /** * Returns a subset of the larger playlist as an ArrayList of all songs by a * particular artist. * @param artistName the passed in name of the artist. * @precondition the array is not empty. * @precondition the artist name is not null. * @return ArrayList of all songs by a particular artist. * * 1. if the playlist array is empty, return null. * 2. if the artist name is null, return null. * 3. create an ArrayList of type E to hold songs. * 4. loop through the entire playlist array: * a. if the current song's artist matches the passed in value, * add it to the arraylist. * 5. { throw new UnsupportedOperationException("Not supported yet."); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started