
kumbirai mangwanda
1,628 PointsNow I'd like to be able to get to the videos by their names,
Can you use the videosByTitle method to generate the proper map of title to video. We'll use it in the next step.
Help please
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;
}
}
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;
}
}
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 video = new Video("The Beginning Bits");
// TODO(2): Add the newly created video to the course videos as the second video.
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

Frederic Saddi
10,594 PointsHey there!
If you remember from a previous lesson, we saw TreeMaps! It's a great way to add elements to a Map, and have them instantly sorted (by Key). Here's the documentation for TreeMap: https://docs.oracle.com/javase/8/docs/api/java/util/TreeMap.html
Hope this helps!
(don't forget to import!)