From 562d6887208f5b0731c369e7167c473725278f0c Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Sat, 26 Oct 2019 19:44:46 -0400 Subject: [PATCH] Add logic for playlist --- .gitignore | 5 ++- src/main/java/io/zipcoder/Music.java | 48 +++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9c9c1d2..becef19 100644 --- a/.gitignore +++ b/.gitignore @@ -46,4 +46,7 @@ atlassian-ide-plugin.xml com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties -fabric.properties \ No newline at end of file +fabric.properties + +# Apple files +*.DS_Store \ No newline at end of file diff --git a/src/main/java/io/zipcoder/Music.java b/src/main/java/io/zipcoder/Music.java index 180c65c..782c13d 100644 --- a/src/main/java/io/zipcoder/Music.java +++ b/src/main/java/io/zipcoder/Music.java @@ -9,6 +9,52 @@ public Music(String[] playList){ } public Integer selection(Integer startIndex, String selection){ - return null; + + int counterCurrentLocation = 0; + int counterUpArrow = 0; + int counterDownArrow = 0; + int counterNumberSteps = 0; + + // up arrow direction + counterCurrentLocation = playList.length - 1; + if (startIndex != playList.length - 1) counterCurrentLocation = startIndex + 1; + counterUpArrow ++; + + + while (counterCurrentLocation != startIndex){ + if (selection.equals(playList[counterCurrentLocation])) { + break; + } + // if we hit the end of the loop, reset and start from beginning of the list + if (counterCurrentLocation >= playList.length - 1){ + counterCurrentLocation = 0; + } + counterCurrentLocation ++; + counterUpArrow ++; + } + + + + // down arrow direction + counterCurrentLocation = 0; + if (startIndex != 0) counterCurrentLocation = startIndex - 1; + counterDownArrow ++; + counterNumberSteps = counterUpArrow; + + while (counterCurrentLocation != startIndex){ + if (selection.equals(playList[counterCurrentLocation])) { + break; + } + // if we hit the end of the loop, reset and start from beginning of the list + if (counterCurrentLocation <= 0){ + counterCurrentLocation = playList.length; + } + counterCurrentLocation --; + counterDownArrow ++; + } + + if (counterDownArrow < counterUpArrow) counterNumberSteps = counterDownArrow; + + return counterNumberSteps; } }