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 Structures Efficiency! Changing Course

help?

Can you please help me with the functions in the QuickFix.java over the next few tasks? I've included other code files for your reference only. I'm going to pass in this course to the addForgottenVideo method. For this task, can you please follow the TODO in the comments in the method.

com/example/model/Course.java
package com.example.model;

import java.util.List;

public class Course {
  private String mName;
  private List<Video> mVideos; 

  public Course(String name, List<Video> videos) {
    mName = name;
    mVideos = videos;
  }

  public String getName() {
    return mName;
  }

  public List<Video> getVideos() {
    return mVideos;
  }

}
com/example/model/Video.java
package com.example.model;

public class Video {
  private String mTitle;

  public Video(String title) {
    mTitle = title;
  }

  public String getTitle() {
    return mTitle;
  }

  public void setTitle(String title) {
    mTitle = title;
  }

}
QuickFix.java
import com.example.model.Course;
import com.example.model.Video;

import java.util.Map;

public class QuickFix {

  public void addForgottenVideo(Course course) {

    mTitle video = new TitleVideo("The Beginning Bits"); 
    // TODO(1):  Create a new video called "The Beginning Bits"
  mVideos.addCourse("second video");
    // TODO(2):  Add to the course videos as the second video.
  }

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

  }

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

}

6 Answers

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey there Admire,

For the first task you first want to import a list to add this to,

Thank Craig passes in a course as an argument so we can just use that and the get videos method from course

List<Video> = videoList = course.getVideos();

Should do the trick, next we will want to create the Video and give it the title "The Beginning Bits, Craig wants this added in position to, thankfully List.add gives us the option to dictate what index this goes into.

Video video = new Video("The Beginning Bits");

Finally, we need to add this in the second position in the list

videoList.add(1, video);

After everything your code should look like below.

public void addForgottenVideo(Course course) {
    List<Video> videoList = course.getVideos();
    Video video = new Video("The Beginning Bits");

    videoList.add(1, video);
  }

Thanks I hope this helps, shout at me if it doesn't.

Jack McDowell
Jack McDowell
37,797 Points

Thanks! And btw I just got frustrated and did

import java.util.*

at the beginning :)

jhonatan gonzales
jhonatan gonzales
2,950 Points

i have a questions connecting to this challenge can someone please in detail break down how and why we would use, List<Video> videoList = course.getVideos();

Please :)

Need to import

import java.util.List;

Gagandeep Virk
Gagandeep Virk
19,741 Points

If you could take a look in Course.java, getVideos() return a generic List. That's why you would use List<Video> to call the getVideos().

Mohit Ladia
Mohit Ladia
4,140 Points

Hi rob , why we need to apply the get videos method from the course class.