Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 75 additions & 2 deletions src/main/java/io/zipcoder/Music.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,83 @@ public class Music {
private String[] playList;

public Music(String[] playList){

this.playList = playList;
}

public Integer selection(Integer startIndex, String selection){
return null;
public int MoveForward(int currentPosition)
{
int nextPosition = 0;
if (currentPosition != playList.length-1)
{
nextPosition = currentPosition+1;
}
else nextPosition = 0;

return nextPosition;

}

public int MoveBackward(int currentPosition)
{
int nextPosition = 0;
if (currentPosition != 0)
{
nextPosition = currentPosition-1;
}
else nextPosition = playList.length-1;

return nextPosition;
}

public Integer selection(Integer startIndex, String selection)
{
Integer noClickForward = 0;
Integer noClickBackward = 0;
//forward
int currentIndex = startIndex;
int nextIndex = MoveForward(currentIndex);
for (int i=0; i<playList.length ; i++)
{
if (playList[nextIndex].equalsIgnoreCase(selection))
{
i=playList.length;

}
else
{
currentIndex++;
nextIndex = MoveForward(currentIndex);

}
noClickForward++;
}

currentIndex = startIndex;
nextIndex = MoveBackward(currentIndex);
for (int i=0; i<playList.length ; i++)
{
if (playList[nextIndex].equalsIgnoreCase(selection))
{
i=playList.length;

}
else
{
currentIndex++;
nextIndex = MoveBackward(currentIndex);

}
noClickBackward++;
}

if (noClickForward>noClickBackward)
{
return noClickBackward;
}
else {
return noClickForward;
}

}
}