Java Java Data Structures Efficiency! Changing Course

Jack Cummins
Jack Cummins
17,402 Points

Please help me!

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?

Please Help by giving me code! Then I can actually get it!

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) {

public void addForgottenVideo(Course course) {
    // TODO(1):  Create a new video called "The Beginning Bits"
// Just use the Video class that is provided for you
    Video video = new Video("The Beginning Bits"); 

    // TODO(2):  Add the newly created video to the course videos as the second video.
// You can specify the index with the add method, but remember arrays start with 0
//  so second place is 1. 
    course.getVideos().add(1, video); 
  }
  }

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

  }

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

}

1 Answer

Brendon Butler
Brendon Butler
4,235 Points

Your QuickFix.java class has a method wrapped in another method. I assume this was a simple mistake.

public void addForgottenVideo(Course course) { // remove this

    public void addForgottenVideo(Course course) {
        // TODO(1):  Create a new video called "The Beginning Bits"
        // Just use the Video class that is provided for you
        Video video = new Video("The Beginning Bits"); 

        // TODO(2):  Add the newly created video to the course videos as the second video.
        // You can specify the index with the add method, but remember arrays start with 0
        //  so second place is 1. 
        course.getVideos().add(1, video); 
    }
} // remove this

You'll want to remove the first addForgottenVideo() method and be sure to remove its closing curly brace, like this:

public void addForgottenVideo(Course course) {
    // TODO(1):  Create a new video called "The Beginning Bits"
    // Just use the Video class that is provided for you
    Video video = new Video("The Beginning Bits"); 

    // TODO(2):  Add the newly created video to the course videos as the second video.
    // You can specify the index with the add method, but remember arrays start with 0
    //  so second place is 1. 
    course.getVideos().add(1, video); 
}