From 96e698307a44a89e9cf12ba998fa7063eaeba21e Mon Sep 17 00:00:00 2001 From: Kai Shields Date: Sat, 26 Oct 2019 19:00:43 -0400 Subject: [PATCH 1/2] completed lab --- .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 | 11 ++++++++++- src/test/java/io/zipcoder/MusicTest.java | 12 ++++++++++++ target/classes/io/zipcoder/Music.class | Bin 0 -> 889 bytes target/test-classes/io/zipcoder/MusicTest.class | Bin 0 -> 1620 bytes 9 files changed, 81 insertions(+), 1 deletion(-) 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/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..031ba89 100644 --- a/src/main/java/io/zipcoder/Music.java +++ b/src/main/java/io/zipcoder/Music.java @@ -9,6 +9,15 @@ public Music(String[] playList){ } public Integer selection(Integer startIndex, String selection){ - return null; + int numberOfClicks = 0; + for (int currentIndex = startIndex; currentIndex < playList.length; currentIndex++) { + String currentSong = playList[currentIndex]; + if(currentSong.equals(selection)){ + break; + } + numberOfClicks++; + + } + return numberOfClicks; } } diff --git a/src/test/java/io/zipcoder/MusicTest.java b/src/test/java/io/zipcoder/MusicTest.java index 03ede61..eaceeab 100644 --- a/src/test/java/io/zipcoder/MusicTest.java +++ b/src/test/java/io/zipcoder/MusicTest.java @@ -24,6 +24,18 @@ public void selectionTest2(){ Music music = new Music(playlist); Integer startingIndex = 0; String selection = "liveoak"; + Integer expected = 2; + Integer actual = music.selection(startingIndex, selection); + Assert.assertEquals(expected, actual); + } + + @Test + public void selectionTest3(){ + + String[] playlist = {"dancinginthedark","rio","liveoak","liveoak"}; + Music music = new Music(playlist); + Integer startingIndex = 0; + String selection = "rio"; Integer expected = 1; Integer actual = music.selection(startingIndex, selection); Assert.assertEquals(expected, actual); diff --git a/target/classes/io/zipcoder/Music.class b/target/classes/io/zipcoder/Music.class new file mode 100644 index 0000000000000000000000000000000000000000..5cbf3734596ebb5fa905078e53ea6684df4b957e GIT binary patch literal 889 zcmZuv%Wl&^6g^`*apRh{Nl2iS0x5;&Q5qg9iw0#=sZylSEP}FtmE%ss6f-W4T>cYgf(eg@zkHY}L9nnM=L7OvsCg&U}- z*NTaoCRQ0{4n5~hSByi3;v#hv5Xw$KBYZB#MAj94^Q|~^DK}_7j>f_zvfP+^+zo{< z8Mdk^IUO1D5f54^C{b8TL4TtdX5A{y$phm2|9|bPo5vpS=Ze&BT*|2cS#td>MZrfNx)kMuk9Ss}nxWkbD zZvYGnQ=Prx0ZoEIuc{g6r;bDmtxm{r;CK=7QV_{cWlx4f+vBey$0M1g^fV{6TeYVQ z=8>w<+gJPToHt8U==YfPn;10J4ZSpaTbQNOCToXmjc%*{6|CO)0_{^AbAiq|=yaMe z;>;Y`KzS04c`T4cd9jZcfIJFG%?}ilCEuprZk$4YXq1flXJ}{dQBilvxWAQI%&ecn zc!%r>>|>oB8|>uw&*g8(e56DTihhMkgG4H;K;%nAx=OTbWYr0~i&8A9O=QYf#6@H% jr%HI4M3aDjGB{|CKLl zH2UO|f0XeXXlNCT#>77C%$z;vJKt~4_S^T5UjWSGZWe# zkY&O}y<5oQ5-!`gV&kffYZk6ss2a#DDPP4m4Wvrth5_?#(2@oQYRZ?7lFc<4J`rmk zBTg-Fh1U?F(&tXljMr6UV5Fvk${V%ivNo(dOd{nzkx{&8ARkFjy0Hp;9hf&@Z+YUi zr=r-v@YC9c*cKH}`0YwP4wc_#MS4@0^X-03zU_}<5ys41@munh&gx36__1uukXeWJ zx@zCujJ+nde6>YevPFL3#)&x%m%6aW4haouB{nZ;oFW057A}L=7iD(Pu6K5?5{Wu5{?j5>X zC%^O}xhdjUhO}q7(v_YP28Q+xLU&rUu$03M+|1z=ZdtgU!!qu$S4;RV#gref%a#bA z^D78dKtWG!%Rumabf2K+|H=94+6M2^z_HQ+1J&QuP?xeZBX-ypULseY>9Un_&y2cL ztd&=XlsnFxx5ous2N t(vAODx~YGs>#v%6h<~2lS#nL1?i}f+NLM6XiF9SsP5)QAA}82~(hq8XLpT5c literal 0 HcmV?d00001 From 70454320c6833aef8fc53947a6c22b4ec19ebf48 Mon Sep 17 00:00:00 2001 From: Kai Shields Date: Sun, 27 Oct 2019 13:39:41 -0400 Subject: [PATCH 2/2] Completed lab. changes made --- src/main/java/io/zipcoder/Music.java | 21 +++++++++++++----- src/test/java/io/zipcoder/MusicTest.java | 12 ---------- target/classes/io/zipcoder/Music.class | Bin 889 -> 976 bytes .../test-classes/io/zipcoder/MusicTest.class | Bin 1620 -> 1381 bytes 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/main/java/io/zipcoder/Music.java b/src/main/java/io/zipcoder/Music.java index 031ba89..85626e0 100644 --- a/src/main/java/io/zipcoder/Music.java +++ b/src/main/java/io/zipcoder/Music.java @@ -9,15 +9,24 @@ public Music(String[] playList){ } public Integer selection(Integer startIndex, String selection){ - int numberOfClicks = 0; + int forwardCount = 0; + int backwardCount = 0; + for (int currentIndex = 0; currentIndex <= startIndex ; currentIndex++) { + forwardCount++; + if (playList[currentIndex].equals(selection)) { + break; + } + } for (int currentIndex = startIndex; currentIndex < playList.length; currentIndex++) { - String currentSong = playList[currentIndex]; - if(currentSong.equals(selection)){ + backwardCount++; + if (playList[currentIndex].equals(selection)) { break; } - numberOfClicks++; - } - return numberOfClicks; + if (forwardCount > backwardCount) { + return backwardCount; + } else { + return forwardCount; + } } } diff --git a/src/test/java/io/zipcoder/MusicTest.java b/src/test/java/io/zipcoder/MusicTest.java index eaceeab..03ede61 100644 --- a/src/test/java/io/zipcoder/MusicTest.java +++ b/src/test/java/io/zipcoder/MusicTest.java @@ -24,18 +24,6 @@ public void selectionTest2(){ Music music = new Music(playlist); Integer startingIndex = 0; String selection = "liveoak"; - Integer expected = 2; - Integer actual = music.selection(startingIndex, selection); - Assert.assertEquals(expected, actual); - } - - @Test - public void selectionTest3(){ - - String[] playlist = {"dancinginthedark","rio","liveoak","liveoak"}; - Music music = new Music(playlist); - Integer startingIndex = 0; - String selection = "rio"; Integer expected = 1; Integer actual = music.selection(startingIndex, selection); Assert.assertEquals(expected, actual); diff --git a/target/classes/io/zipcoder/Music.class b/target/classes/io/zipcoder/Music.class index 5cbf3734596ebb5fa905078e53ea6684df4b957e..25dfdd46f5da3d738f679edd360eb2bbc1905b2e 100644 GIT binary patch delta 324 zcmZ{fy-EW?6otR}+ZZsKs2eqL8#Rrw(PA4Rjg5t1rH$2UNTFaLD3)pR2B~bLkT#$M zE1$tP(ATiivq9`+;Bd~|@19}4qW8kYnqkAF!?LMvbh^F!tk*v5-rd|9N*CGX^ajX)*0kXWOR8Fz^#W=_EcG8vNiq-s delta 251 zcmcb>{*!G36Qcrma%oXfYFFVp*boPGVlVesD=qW?uTl|CaoGd8N5Y zsYU*2&N-RM*~Oc)7{eIr8P+l|F|aW(FqksiX>Vg-He(TG(b~emv~LlEB8V1cF|uNn zWYyWmz%rA8Z8-x^3o~O23*++tw`F%QuxlcE4o%7pz#AkvlJ5m delta 195 zcmWlTyG{Z@07cKRV`eg0l*+_{knnz}$WvL~NJmSljb;lHf(4XR)Kblt5IPDzz}gRh zM1F&~G&iR>C%Gr{>kfa;yFF0i)es@4$ZHCkd(DI9QBgD~o=hN=FH|v9scGt(XU&VE zq3|}tk+`{@`&0jOG5MN}{rRF|*W&xOsc5;h>A1w`Dtaz`2HRq&EQH*CIB&upoV5Lu pOS_T{8TO>KM<*3ca7U6jDKexf1Y07DM=r?oR$RTSOz=5G_8+H)A|n6*