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
Rob Bridges
14,945 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
18,329 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.

Jeffrey Lewis
PRO
Jeffrey Lewis
Pro Student 6,028 Points

TODO #2 course.getVideos().add(1,video);