Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java: Finish all unfinished methods in Playlist.java. Implement an ARRAY that stores the data, and will mak use of a method to expand it if

Java:

Finish all unfinished methods in Playlist.java. Implement an ARRAY that stores the data, and will mak use of a method to expand it if it reaches max capacity. You must test the Playlist by writing Junit test cases.

These must be implemented in all unimplemeneted methods:

boolean add(E element)

void expandCapacity()

E shufflePlay()

void clearPlayList()

int size()

boolean isEmpty()

ArrayList createSmartPlayList(E song)

ArrayList getAllSongsonAlbum(String albumName)

---------------------------------

import java.util.ArrayList;

/** * An interface for a PlayList, which will function similarly to a simplified * ArrayList. * @author Brian Thompson * @version 2017-1-17, version 2.0 * @param Generic element */ public interface PlaylistADT { /** * 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 */ public boolean add(E element); /** * Removes a specified song from the array. * @param element the song to be removed * @return true/false if the song was removed * @precondition if the array is not empty * @precondition element is not null * @precondition if the song is in the playlist array * * 1. if the playlist array is empty or the passed-in element is null, return false. * 2. if the song isn't in the playlist array, return false * 3. remove the song from the array, but make sure you don't leave any * empty slots in the array. This can be done by swapping or by shifting. * **if you decide to use swapping, be sure to change the removed element * to null** * 4. decrement size counter. * 5. return true */ public boolean remove(E element); /** * Removes a random song from the array to be played - removes it so it * isn't played again. * @precondition the playlist array is not empty. * @return the randomly removed song. * * 1. If the playlist array is empty, return null. * 2. Otherwise: * a. generate a random integer using the size of the array to determine * the index from which we will remove a song. * b. store this song in a temp variable. * c. you may use the remove method that has been coded for you above, or * recode the swap process. * d. decrement size counter. * e. return the temp variable. */ public E shufflePlay(); /** * Plays the song at the specified index, but does not remove it from the playlist. * @precondition the collection is not empty. * @precondition the index is valid * @param index the passed in index of the song * @return a copy of the song to be played. * * 1. if the array is empty, return false * 2. Check if the index is valid (isn't < 0 or >= size) * 3. Create a temp variable E temp; * 4. Store the song in the temp variable. * 5. Return temp. */ public E play(int index); /** * Returns the index of the song to be played. * @precondition the passed-in element is not null * @precondition the array is not empty * @precondition the song is in the array. * @param element the song to be found * @return the index of the element * * 1. if the array is empty, return -1; * 2. if the passed in element is null, return -1; * 3. * 4. otherwise: * a. loop through the array and return the index of the song, or -1 if not found. */ public int search(E element); /** * Determines if the song is in the array. * @precondition the array is not empty * @precondition the element is not null * @param element the song for which we are searching. * @return true/false if the song is in the array. * * 1. if the array is not empty and the passed in element is not null: * a. loop through the entire array: * - if the song is found, return true. * 2. otherwise, return false. */ public boolean contains(E element); /** * Clears all elements in the array. * 1. create a new array and overwrite the current one with it. * 2. reset the size counter to 0. */ public void clearPlaylist(); /** * Gets the number of songs in the playlist. * return the size counter. * @return the size of the playlist. */ public int size(); /** * Returns true/false if the array is empty * @return true if the array is empty, false otherwise. */ public boolean isEmpty(); /** * Returns a subset of the larger playlist as an ArrayList of songs that * have the same genre. * @param song * @precondition the playlist is not empty. * @precondition the passed-in element is not null * @return an array list of all songs with the same genre. * * 1. if the playlist array is empty or the passed-in element is null, return null. * 2. otherwise: * a. create an ArrayList with generic type E to hold songs. * a. loop through the entire playlist array * i. if the current song has the same genre as what was passed in, * add it to the ArrayList. * 3. return the ArrayList. */ public ArrayList createSmartPlaylist(E song); /** * 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. return the array list. */ public ArrayList getAllSongsByArtist(String artistName); /** * Returns all the songs on a single album. * @precondition the array is not empty. * @precondition the album name is not null. * @param albumName the passed in name of the album. * @return an array list of all songs on a particular album. * * 1. if the playlist array is empty, return null. * 2. if the album 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 album is the same as the passed in value, * add it to the arraylist. * 5. return the array list. */ public ArrayList getAllSongsOnAlbum(String albumName); /** * toString method for playlist. * @return a string representation of all the songs in the playlist. */ @Override public String toString(); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

What attracts you about this role?

Answered: 1 week ago

Question

How many states in India?

Answered: 1 week ago

Question

HOW IS MARKETING CHANGING WITH ARTIFITIAL INTELIGENCE

Answered: 1 week ago

Question

Develop clear policy statements.

Answered: 1 week ago

Question

Draft a business plan.

Answered: 1 week ago

Question

Describe the guidelines for appropriate use of the direct plan.

Answered: 1 week ago