Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Java Data Structure last Code Challenge

I don't understand why, and from where, the object "course" is used on this line of the code.

The code line

course.getVideos().add(1, newVideo);

The entire code

import com.example.model.Course;
import com.example.model.Video;

import java.util.Map;

public class QuickFix {

  public void addForgottenVideo(Course course) {
    // TODO(1):  Create a new video called "The Beginning Bits"
    Video newVideo = new Video("The Beginning Bits");

    // TODO(2):  Add the newly created video to the course videos as the second video.
     course.getVideos().add(1, newVideo);

  }

  public void fixVideoTitle(Course course, String oldTitle, String newTitle) {

  }

  public Map<String, Video> videosByTitle(Course course) {
    return null;
  }

}

1 Answer

The object "course" is the one passed in as an argument. The method addForgottenVideo takes a course as an argument. Whatever course object that is, that's the one the video will be added to.