method called backward() that allows users to move back to the previous song in
ID: 3528349 • Letter: M
Question
method called backward() that allows users to move back to the previous song in the playlist. Create this method based upon the code for the forward() method. Annotate your code with comments and test it properly. Use good coding practices, including naming standards and appropriate white space. ============================== public void forward() { if (state.equals("playing")) { Mp3 song = songs.get(currentSongPlaying); song.stop(); if (songs.size()-1>currentSongPlaying) { currentSongPlaying = currentSongPlaying + 1; song = songs.get(currentSongPlaying); song.play(this); } else if (songs.size()-1==currentSongPlaying) { state="notPlaying"; }Explanation / Answer
public void backward() {
if (state.equals("playing")) { //if mp3player is playing now
Mp3 song = songs.get(currentSongPlaying);//get the current song playing
song.stop(); // and stop it
if (currentSongPlaying>0) {
//if this song is not first song in the playlist assuming first song number is 0
currentSongPlaying = currentSongPlaying - 1;//go to previous song number
song = songs.get(currentSongPlaying); // and get that song
song.play(this); } // and play that song
else if (currentSongPlaying==0) {//if no more songs before this song to play
state="notPlaying"; //change the mp3 player from playing to not playing
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.