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 trialJack Cummins
17,417 PointsPlease 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!
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) {
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
4,254 PointsYour 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);
}