From d6f9ec13b94da14f1a40ddb042f2d211132d3056 Mon Sep 17 00:00:00 2001 From: Eric Cordell Date: Fri, 2 Mar 2018 14:35:31 -0500 Subject: [PATCH] trying to submit --- PlaylistChallenge.iml | 4 ++ pom.xml | 5 +++ src/main/java/io/zipcoder/Music.java | 40 ++++++++++++++++-- target/classes/io/zipcoder/Music.class | Bin 0 -> 997 bytes .../test-classes/io/zipcoder/MusicTest.class | Bin 0 -> 1381 bytes 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 target/classes/io/zipcoder/Music.class create mode 100644 target/test-classes/io/zipcoder/MusicTest.class diff --git a/PlaylistChallenge.iml b/PlaylistChallenge.iml index 54ddd53..6098888 100644 --- a/PlaylistChallenge.iml +++ b/PlaylistChallenge.iml @@ -13,5 +13,9 @@ + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index bbd82c1..cd17122 100644 --- a/pom.xml +++ b/pom.xml @@ -16,5 +16,10 @@ 4.12 test + + junit + junit + RELEASE + \ 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..14d1e86 100644 --- a/src/main/java/io/zipcoder/Music.java +++ b/src/main/java/io/zipcoder/Music.java @@ -1,14 +1,48 @@ package io.zipcoder; + public class Music { private String[] playList; - public Music(String[] playList){ + public Music(String[] playList) { this.playList = playList; } - public Integer selection(Integer startIndex, String selection){ + public Integer selection(Integer startIndex, String selection) { + + + int indexOfSelection = 0; + + for (int i = 0; i < playList.length; i++) { + + if (playList[i].equals(selection) && (playList.length - i < startIndex + i)) { + indexOfSelection += i; + } + } + + //if startIndex is BEFORE the indexSelection + // [startIndex selectionIndex] + + if (indexOfSelection > startIndex) { + + //(left side count VS right side count) + if (indexOfSelection - startIndex < (startIndex + playList.length - indexOfSelection)) { + return indexOfSelection - startIndex; + } + return startIndex + playList.length - indexOfSelection; + } + + //if startIndex is AFTER the indexSelection + // [selectionIndex startIndex] + if (indexOfSelection < startIndex) { + + //(left side count VS right side count) + if (startIndex - indexOfSelection < (indexOfSelection + playList.length - startIndex)) { + return indexOfSelection + playList.length - startIndex; + } + return startIndex - indexOfSelection; + } return null; } -} +} \ No newline at end of file diff --git a/target/classes/io/zipcoder/Music.class b/target/classes/io/zipcoder/Music.class new file mode 100644 index 0000000000000000000000000000000000000000..fa34923102b3e4feaf25db6f08f4569fd2bcd3df GIT binary patch literal 997 zcmZuwO-~b16g_V`W!iCo7APt>D1NpDsSZwho0Smr{p>QW@$AHq`z4a7P<=FjjK8Up&G zcFPqQtx4Z~(tWk=22Y)JkH}c9-E_Q$6G&wrgL?Q`B*zuKXfwu(-9id!12-((#4Q7P3k4J{%wb+2`=3&Q%%GF{ z`W7V%B=TyQF-N}{-hjK)bv({27oSL;5?oWz$xD+nLTj=g zjZtK1kr!pu4d1>$qX#rj1)RZdNAPeu9iS+ct&!ws?JG2>JM zS9qHuRQldbn(?-Z3=CCNPZ%sRnjg!C3|ZBA%&K*_ zDvn8P`F4-8WS#zn8z;guP1?v~n8ktps7Cw3BdBrBj_P7|2$G zBy{CtrKgoY9>Sca&!GiZ)S>{xQHHpPWqPu&A{QapSKcEgJ*i` z6O0cGI&g;1%waNv0miwb0t{k^Hv?zc+;Q0a9VS0PVAcAHj#|n|RcoeWR%>Y|U9DxD zOtta_R&Dwd?5E}dI-fb2vYBR3PS4C1%#X;HGlg^^bAYZE^EhlGcA-Gtadcw>c}!FM zJmr@ue1+^<)srLUrm6yp>^Mhtfj?w8Q zqG`XEc^bI#S9dw>u3NjyYj^oJcd0{n`Ld~P{@dLUwVow=ff~DFXli literal 0 HcmV?d00001