From 704ef7ba64996280b52f907d372002acee0a804a Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 24 Oct 2019 14:52:32 -0400 Subject: [PATCH] Implement playlist --- .gitignore | 6 +++++- pom.xml | 4 ++++ src/main/java/io/zipcoder/Music.java | 20 +++++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9c9c1d2..6ede73c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,10 @@ .idea/**/tasks.xml .idea/dictionaries +target/ +.idea/ +*.iml + # Sensitive or high-churn files: .idea/**/dataSources/ .idea/**/dataSources.ids @@ -46,4 +50,4 @@ atlassian-ide-plugin.xml com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties -fabric.properties \ No newline at end of file +fabric.properties diff --git a/pom.xml b/pom.xml index bbd82c1..c3dd5a4 100644 --- a/pom.xml +++ b/pom.xml @@ -8,6 +8,10 @@ PlaylistChallenge 1.0-SNAPSHOT + + 1.8 + 1.8 + diff --git a/src/main/java/io/zipcoder/Music.java b/src/main/java/io/zipcoder/Music.java index 180c65c..7258b8c 100644 --- a/src/main/java/io/zipcoder/Music.java +++ b/src/main/java/io/zipcoder/Music.java @@ -9,6 +9,24 @@ public Music(String[] playList){ } public Integer selection(Integer startIndex, String selection){ - return null; + + int count = 0; + for (int i = startIndex; !playList[i].equals(selection); i++) { + if(i == playList.length - 1) { + i = -1; + } + count++; + } + + int revCount = 0; + for (int i = startIndex; !playList[i].equals(selection); i--) { + if(i == 0) { + i = playList.length; + } + revCount++; + } + + if(count < revCount) { return count; } + else { return revCount; } } }