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 trialKyle Salisbury
Full Stack JavaScript Techdegree Student 16,363 Points3 0f 3 challenge for last Java data structures quiz.
I'm really lost to even know where to begin. Craig gives a hint that I should use the videosByTitle method, but I have no idea how to search for a video title and switch 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;
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Arrays;
public class QuickFix {
public void addForgottenVideo(Course course) {
Video newVideo = new Video("What up?");
course.getVideos().add(1, newVideo);
}
public void fixVideoTitle(Course course, String oldTitle, String newTitle) {
}
public Map<String, Video> videosByTitle(Course course) {
Map<String, Video> byTitle = new TreeMap<String, Video>();
for (Video video : course.getVideos()) {
byTitle.put(video.getTitle(), video);
}
return byTitle;
}
}
1 Answer
Christopher Augg
21,223 PointsKyle,
No problem. I will provide you with some pseudocode to get you on track.
public void fixVideoTitle(Course course, String oldTitle, String newTitle) {
// Create a map and assign it the videosByTitle method. Make sure to pass in course.
// Create a video and assign it using the map's get method. Pass in the oldTitle to get the video we want.
// set the title of this video to the newTitle using the video's set method
// use the map's put method to place the newTitle and video back into the map
}
Please let me know if this helps. I will explain it in more detail if you need.
Regards,
Chris
Dustin Bryce Flanary
17,663 PointsDustin Bryce Flanary
17,663 PointsI'm having a hard time knowing what parameters to put into the map I create. I assume course and string?