From f7537f877c53c84282ae6b7ec43134b921e7aaf1 Mon Sep 17 00:00:00 2001 From: SandyPham823 Date: Sat, 26 Oct 2019 20:15:41 -0400 Subject: [PATCH] finished lab --- .idea/$PRODUCT_WORKSPACE_FILE$ | 19 ++++++++++++ .idea/compiler.xml | 16 ++++++++++ .idea/misc.xml | 13 ++++++++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 6 ++++ PlaylistChallenge.iml | 16 ++++++++++ src/main/java/io/zipcoder/Music.java | 29 +++++++++++++++--- target/classes/io/zipcoder/Music.class | Bin 0 -> 1011 bytes .../test-classes/io/zipcoder/MusicTest.class | Bin 0 -> 1381 bytes 9 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 .idea/$PRODUCT_WORKSPACE_FILE$ create mode 100644 .idea/compiler.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 PlaylistChallenge.iml create mode 100644 target/classes/io/zipcoder/Music.class create mode 100644 target/test-classes/io/zipcoder/MusicTest.class diff --git a/.idea/$PRODUCT_WORKSPACE_FILE$ b/.idea/$PRODUCT_WORKSPACE_FILE$ new file mode 100644 index 0000000..3733e0d --- /dev/null +++ b/.idea/$PRODUCT_WORKSPACE_FILE$ @@ -0,0 +1,19 @@ + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..2bb69ef --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d30d09e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..5103107 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file 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..d22562b 100644 --- a/src/main/java/io/zipcoder/Music.java +++ b/src/main/java/io/zipcoder/Music.java @@ -4,11 +4,32 @@ public class Music { private String[] playList; - public Music(String[] playList){ + public Music(String[] playList) { this.playList = playList; } - public Integer selection(Integer startIndex, String selection){ - return null; + public Integer selection(Integer startIndex, String selection) { + int leftToRight = 0; + int rightToLeft = 0; + for (int i = startIndex; i < playList.length; i++) { + if (playList[i].equals(selection)) + break; + if (i + 1 > playList.length) + i = -1; + leftToRight++; + } + for (int i = startIndex; i < playList.length; i--) { + if (playList[i].equals(selection)) + break; + if (i - 1 < 0) + i = playList.length; + rightToLeft++; + } + + if(leftToRight < rightToLeft) { + return leftToRight; + } + return rightToLeft; } -} + +} \ 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..68ce933af315df59a1f6b78b1ed06b8d066370b5 GIT binary patch literal 1011 zcmZuwUr*Ce96h&dSJq8oKvBV|h~oYrix`Lz!;6NvWR64#4{D-ilyOOEvFnH$Uo;p# zgNaYXgjY=zjSqYPpY#if=WfUrN zEV}~TW$C+>#`=;QE;vgbGri@Y>UfJzC{=uz)T32d=V4_T6ko}WDzRblL8C6KJSYX^q+iVp-*Cx?MQr%FB{|wCH#Zp35f6>p-`t^S<2Y4acLycBg-> z+0(g40_LWgFt?&^v~-et80Pn4^7|3clp5|d?kyy_rWnmK*7&ya-yrgZuh2d>dromZ zjTl!GdJ~yo3=Fio(TyHP#5HTYAf(aTnkgpP6K8EZHWQoD3wwx78McxC0&RZ>W9n@i z6JvYO-y^<@A=}WOHH#k+*QSiEnAkGJ?!m8Pz`}9hAc4yt$XpF3PABeQ_uzNN)_2gA z`3~cgt*ez(G$=t8^l?o!BZG2m${3-LQIek^{YlnuF+amfg;Jm344&dFR&WmM7{mti zo5u4d1>$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