Okay so my loop is supposed to check if an item in the ArrayList has the MINIMUM_RATING value which is 1. It does that just fine, but the problem starts when there is more than one item with the MINIMUM_RATING value in it. I need it to stop at the first item with that value in it. Here is the method I wrote.
public int getFirstIndexWithMinRating() {
String minName = "";
for(Track nextTrack : tracks) {
if (nextTrack.getRating() == Track.MINIMUM_RATING)
minName = nextTrack.getName();
}
return indexOf(minName);
}
and here is the test method that I wrote that showed me the problem.
public void testShouldReturnOneWhenSecondAndLastSongHasMinRating() {
theTracks = new Playlist("mo");
theTracks.add(new Track("song 1", 2));
theTracks.add(new Track("song 2", 1));
theTracks.add(new Track("song 3", 6));
theTracks.add(new Track("song 4", 1));
assertEquals(1, theTracks.getFirstIndexWithMinRating())
The value returned is 3 and I need it stop at song 1. Any help would be greatly appreciated.