From ed97230cdff131b0029560d70ee915403f880026 Mon Sep 17 00:00:00 2001 From: Keerthana Srinivasan Date: Sun, 21 Nov 2021 01:13:42 -0500 Subject: [PATCH] Completed Lab --- PlaylistChallenge.iml | 16 ++++++++++++++++ src/main/java/io/zipcoder/Music.java | 12 +++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 PlaylistChallenge.iml diff --git a/PlaylistChallenge.iml b/PlaylistChallenge.iml new file mode 100644 index 0000000..0ddf51c --- /dev/null +++ b/PlaylistChallenge.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ 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..891bfeb 100644 --- a/src/main/java/io/zipcoder/Music.java +++ b/src/main/java/io/zipcoder/Music.java @@ -9,6 +9,16 @@ public Music(String[] playList){ } public Integer selection(Integer startIndex, String selection){ - return null; + int count = 0; + int upCount = 0; + + for (int i = 0; i < playList.length; i++) { + if(selection.equals(playList[i])){ + count = Math.abs(startIndex - i); + upCount = Math.abs(startIndex + playList.length - i); + } + + } + return Math.min(count,upCount); } }