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 trialcoder5837
1,535 PointsI have been on this challenge for over three days and I'm very frustrated
I am tired of trying to figure this out on my own can someone just post the completed code for all three challenges with an explanation so I can move on?
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.ArrayList;
import java.util.TreeMap;
import java.util.Map;
import java.util.Arrays
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) {
Map<String, Video> byTitle = new TreeMap<String, Video>();
ArrayList<Video> courseList = new ArrayList<Video>();
courseList.add(course);
for(Video video : courseLIst) {
byTitle.put(video.getName(), video);
}
return byTitle;
}
}
Craig Dennis
Treehouse TeacherHi Emily!
I added some comments, hope they help!
public Map<String, Video> videosByTitle(Course course) {
Map<String, Video> byTitle = new TreeMap<String, Video>();
// The next two lines are not needed, but I commented them.
// REMOVED - ArrayList<Video> courseList = new ArrayList<Video>();
// This is defined as an ArrayList of Videos, but you added a course
// REMOVED - courseList.add(course);
// This was what I was hinting at earlier. Course has getVideos.
for(Video video : course.getVideos()) {
// You had getName(), but it is getTitle()
byTitle.put(video.getTitle(), video);
}
return byTitle;
}
coder5837
1,535 PointsOkay passed that challenge! But I'm having difficulty with the next one: I wasnt sure how to post the code again on this one so I asked a new question- could you answer on that one?
Craig Dennis
Treehouse TeacherThanks Emily can you please choose best answer on this one so no one else thinks this problem is still open.
Thanks!
1 Answer
Craig Dennis
Treehouse TeacherHi Emily,
Remember the course has the ability to get it's videos through the getVideos
method, so you don't need to make a new list.
for(Video video : course.getVideos()) {
Everything else there is looking good.
coder5837
1,535 Pointsthanks for answering but I still completely don't get it can you just post the finished code and explanation so i can move on?
Craig Dennis
Treehouse TeacherNo problem Emily!
What is your current code and error? My answer seems to be what is missing from your code.
I'll help you through it!
coder5837
1,535 Pointshaha thanks! but the code above is my current code I haven't changed it yet because I've been really stuck
Craig Dennis
Treehouse TeacherCan you please do the fixes incrementally and give me the errors you are receiving? I can't just give you the full answer. I'll help you through the parts you are confused on.
coder5837
1,535 Pointsokay so that is my code right now and this is my error:
QuickFix.java:23: error: no suitable method found for add(Course)
courseList.add(course);
^
method Collection.add(Video) is not applicable
(argument mismatch; Course cannot be converted to Video)
method List.add(Video) is not applicable
(argument mismatch; Course cannot be converted to Video)
method AbstractCollection.add(Video) is not applicable
(argument mismatch; Course cannot be converted to Video)
method AbstractList.add(Video) is not applicable
(argument mismatch; Course cannot be converted to Video)
method ArrayList.add(Video) is not applicable
(argument mismatch; Course cannot be converted to Video)
./QuickFix.java:24: error: cannot find symbol
for(Video video : courseLIst) {
^
symbol: variable courseLIst
location: class QuickFix
./QuickFix.java:25: error: cannot find symbol
byTitle.put(video.getName(), video);
^
symbol: method getName()
location: variable video of type Video
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
3 errors
coder5837
1,535 Pointscoder5837
1,535 Pointsoh and could you explain all of the tasks and post the completed code? I'm not sure what I'm doing right now and I really just want to move on to this other course.