Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I urgently need solutions for the questions below package questions; import doNotModify.Song; import doNotModify.SongNode; public class PlayQueue { public SongNode start; / / DO NOT
I urgently need solutions for the questions below
package questions;
import doNotModify.Song;
import doNotModify.SongNode;
public class PlayQueue
public SongNode start; DO NOT MODIFY
public SongNode end; DO NOT MODIFY
You may add extra attributes here
Adds a Song to the end of the PlayQueue.
Note: This must be completed before moving onto any other method.
@param song The Song to add
public void addSongSong song
TODO: To be completed
Remove the first SongNode with the parameter Song from the PlayQueue.
Return true if a SongNode was removed, false otherwise.
@param song
@return true if a SongNode was removed, false otherwise.
public boolean removeSongSong song
return false; TODO: To be completed
Removes the SongNode at the specified index from the PlayQueue, returning
the Song that was removed.
Return null if index is invalid.
@param index
public Song removeSongint index
return null; TODO: To be completed
Return the size number of SongNodes in the PlayQueue.
@return the size of the PlayQueue
public int size
return ; TODO: To be completed
Reverse the calling object PlayQueues Song ordering.
public void reverseQueue
TODO: To be completed
Move the SongNode from the fromIndex index the specified amount
Let the queue be:
start end
null a b c d null
Let fromIndex be
The expected queue should be as follows for:
amount :
start end
null a b c d null
amount :
start end
null a c b d null
amount :
start end
null b a c d null
amount :
start end
null a c d b null
Do nothing if either fromIndex is invalid, or amount is invalid for
the given fromIndex
Do not create any new SongNode instances.
@param fromIndex
@param amount
public void moveSongint fromIndex, int amount
TODO: To be completed
Swap the SongNodes at parameter indices.
Do nothing if either parameters are invalid.
@param firstIndex
@param secondIndex
public void swapSongsint firstIndex, int secondIndex
TODO: To be completed
Check the PlayQueue for cycles.
There is at most one cycle in the PlayQueue. This may be bidirectional.
@return true if a cycle is detected, false otherwise.
public boolean hasCycle
return false; TODO: To be completed
Create and return a semi randomly shuffled PlayQueue from the calling object.
A shuffled PlayQueue begins with the same Song as the calling object.
For all other Songs in the resulting PlayQueue the following formula is used:
x p s n
where x is the index previously taken from,
where p is a prime number,
where s is seed number.
and n is the length of the PlayQueue
You must ensure that you do not go out of bounds, and that when the provided formula
creates a cycle that it is no longer used. Then the Songs in all uncovered SongNodes
are added in their original order to the resulting PlayQueue.
@param p prime number
@param s seed number
@return the shuffled queue
public PlayQueue shuffledQueueint p int s
return null; TODO: To be completed
@Override
public String toString
if start null
return "null";
String forward forwards : ;
SongNode temp start;
while tempnext null
forward temp.song.title ;
temp temp.next;
forward temp.song.title null";
temp end;
String backward ;
while tempprevious null
backward temp.song.title backward;
temp temp.previous;
backward "backwards : null temp.song.title backward;
return forward
backward;
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