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 Pointswhat am I doing wrong?
this is my error message: ./QuickFix.java:18: error: '(' expected if newVideoMap.containsKey(oldTitle) { ^ ./QuickFix.java:18: error: ')' expected if newVideoMap.containsKey(oldTitle) { ^ ./QuickFix.java:17: error: cannot find symbol Map newVideoMap = videosbyTitle(course); ^ symbol: method videosbyTitle(Course) location: class QuickFix ./QuickFix.java:19: error: method put in interface Map cannot be applied to given types; newVideoMap.put(newTitle); ^ required: String,Video found: String reason: actual and formal argument lists differ in length where K,V are type-variables: K extends Object declared in interface Map V extends Object declared in interface Map ./QuickFix.java:22: error: incompatible types: unexpected return value return newVideoMap; ^ 5 errors
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) {
Map<String, Video> newVideoMap = videosbyTitle(course);
if newVideoMap.containsKey(oldTitle) {
newVideoMap.put(newTitle);
newVideoMap.remove(oldTitle);
}
return newVideoMap;
}
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;
}
}
coder5837
1,535 Pointsokay so this is my code now: what do I do with the first Map? There always seems to be an error on it.
public void fixVideoTitle(Course course, String oldTitle, String newTitle) {
Map<String, Video> newVideoMap = videosbyTitle(course);
video.setTitle(newTitle);
}
./QuickFix.java:17: error: cannot find symbol Map newVideoMap = videosbyTitle(course); ^ symbol: method videosbyTitle(Course) location: class QuickFix ./QuickFix.java:18: error: cannot find symbol video.setTitle(newTitle); ^ symbol: variable video location: class QuickFix 2 errors
Craig Dennis
Treehouse TeacherWhat is video there? Did you get
it from somewhere?
coder5837
1,535 PointsI tried putting .getVideos() at the end but it didn't work.
Craig Dennis
Treehouse TeacherRead my answers again. Remember that Map
you have is keyed on the current title and the value is the video with that title.
coder5837
1,535 Pointspublic void fixVideoTitle(Course course, String oldTitle, String newTitle) {
Map<String, Video> newVideoMap = videosbyTitle(course);
Video video = newVideoMap.get(oldTitle);
Video.setTitle(newTitle);
}
this is my code and it's really having a hard time with the course /QuickFix.java:17: error: cannot find symbol Map newVideoMap = videosbyTitle(course); ^ symbol: method videosbyTitle(Course) location: class QuickFix ./QuickFix.java:19: error: non-static method setTitle(String) cannot be referenced from a static context Video.setTitle(newTitle); ^ 2 errors
Craig Dennis
Treehouse TeacherWhy the capital V on video on the last line?
coder5837
1,535 Pointsi changed that but why is the (course) part of my code having so much trouble?
Craig Dennis
Treehouse TeacherLook at the spelling including case. Is it the same?
coder5837
1,535 PointsWAIT NEVER MIND I GOT IT THANK YOU SO MUCH YAYAYAYAYAAYYAAYAAYAYAAAYYAYAAYA
Craig Dennis
Treehouse TeacherWoooooohooooo! Congrats! Way to stick with it!
1 Answer
Craig Dennis
Treehouse TeacherThe first error is because you don't have parens around your if
condition.
For this one, you can get the video out by the old title, and then change the title to the new one.
This works because of object references.
Hope that helps!
coder5837
1,535 PointsI changed the parenthesis but I'm not really sure what you mean by "get the video out by the old title"?
Craig Dennis
Treehouse TeacherMap
s have a get
method that allows you to pull a value out by a key. Your key is oldTitle
. The value returned will be a video that you can set the title on.
coder5837
1,535 PointsSo what part would I change to have the get method?
Craig Dennis
Treehouse TeacherThat is the entire solution. Get the video, change the title.
coder5837
1,535 Pointswhat method should I use to change the title?
coder5837
1,535 Pointswhat method should I use to change the title?
Craig Dennis
Treehouse TeacherLook at the video class...do you see one?
coder5837
1,535 PointsI'm not really sure what's happening right now
Craig Dennis
Treehouse TeacherIn the Video.java
file that you are provided there are two methods. Does one look like something that might let you change the title?
coder5837
1,535 Pointsokay so I changed the code for that one to public void fixVideoTitle(Course course, String oldTitle, String newTitle) { Map newVideoMap = videosbyTitle(course); newVideoMap.setTitle(newTitle);
return newVideoMap; } but I'm still getting this error: ./QuickFix.java:17: error: cannot find symbol Map newVideoMap = videosbyTitle(course); ^ symbol: method videosbyTitle(Course) location: class QuickFix ./QuickFix.java:18: error: cannot find symbol newVideoMap.setTitle(newTitle); ^ symbol: method setTitle(String) location: variable newVideoMap of type Map ./QuickFix.java:20: error: incompatible types: unexpected return value return newVideoMap; ^ 3 errors
Craig Dennis
Treehouse TeacherCraig Dennis
Treehouse TeacherDo you want to set the title on the map, or on the video? Also you don't need to return anything, the methods return type is
void
.Read the hints again. Take your time, you got this.