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 trialMatthew Wadley
1,282 PointsIm lost with where to start
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?
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"
// 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;
}
}
3 Answers
Stephen Wall
Courses Plus Student 27,294 Pointspublic 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);
}
Zach Freitag
20,341 PointsSpoiler Alert!
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"
// 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;
}
}
Dan Johnson
40,533 PointsFor the first part of the challenge you just need to:
- Create a new instance of
Video
with "The Beginning Bits" as the title. - Get the list of videos from the course argument using the getVideos method.
- Add the new video you created to the list of videos you retrieved at index 1.
Matthew Wadley
1,282 PointsI got step 1 of 3, but now I'm stuck on the second part.
Dan Johnson
40,533 PointsFor step two it'll go something like this:
Create a new map
-
For every video in the course video list, put a new key value pair in the map where:
- The key is the video title
- The value is the video reference
Return the map