Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the following pseudo code: public void forward() { if (state.equals(\"play

ID: 3548082 • Letter: G

Question

Given the following pseudo code:
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";
            }
Explain the function of each line of code to get a bird

Explanation / Answer

public void forward() { //This is the name if the method forward

if (state.equals("playing")) { //Check if the song is currently playing

Mp3 song = songs.get(currentSongPlaying); //If yes then assign the variable song with the current song playing

song.stop(); //Stop that song

if (songs.size()-1>currentSongPlaying) { //If the currentsongplaying is not the last one

currentSongPlaying = currentSongPlaying + 1; //Then play the next song from the playlist

song = songs.get(currentSongPlaying); //Once again assign the variable song with the current song playing

song.play(this); //Play that assigned song to the variable song

} else if (songs.size()-1==currentSongPlaying) { //Else if the currentsongplaying is the lastone in the playlist

state="notPlaying"; //Stop playing the songs.

}

}

}


public void backword() {

if (state.equals("playing")) {

Mp3 song = songs.get(currentSongPlaying);

song.stop();

if (currentSongPlaying > 1) {

currentSongPlaying = currentSongPlaying - 1;

song = songs.get(currentSongPlaying);

song.play(this);

} else if (currentSongPlaying == 1) {

state="notPlaying";

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote