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 trial

Java Java Data Structures - Retired Efficiency! Changing Course

set import problem

So here is the error:

./QuickFix.java:19: error: cannot find symbol

Set

Look at my code and please someone tell me the problem.

com/example/model/Course.java
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;
  }

}
com/example/model/Video.java
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;
  }

}
QuickFix.java
import com.example.model.Course;
import com.example.model.Video;
import java.util.List;
import java.util.Set;
import java.util.HashMap;
import java.util.Map;

public class QuickFix {

  public void addForgottenVideo(Course course) {
    List<Video> newList = course.getVideos();
    // 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.
   newList.add(1, video);
  }

  public void fixVideoTitle(Course course, String oldTitle, String newTitle) {
   Set<Video> allVideos = videosByTitle(course).valueSet();
    for (Video video : allVideos) {
     if (video.getTitle() == oldTitle) {
       videosByTitle(course).remove(oldTitle, video);
       videosByTitle(course).put(newTitle, video);
     }
   }
  }

  public Map<String, Video> videosByTitle(Course course) {
    Map<String, Video> videoMap = new HashMap<String, Video>();
    for (Video video : course.getVideos()) {
      videoMap.put(video.getTitle(), video);
    }
    return videoMap;
  }

}

3 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

The goal of this one is to pull out the course by the old title and then set the title properly on that course. Don't worry about modifying the collection, it gets generated each time.

I forgot about the setTitle() method. Looks like I overthought it. Thanks for the help Craig Dennis. :)

Ker Zhang
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ker Zhang
Full Stack JavaScript Techdegree Graduate 29,113 Points

While running your code, I got same error and didn't know how to fix it. However, this solution for this challenge could be simplified in this way:

public void fixVideoTitle(Course course, String oldTitle, String newTitle) { videosByTitle(course).get(oldTitle).setTitle(newTitle); }

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

video.getTitle() == oldTitle

Remember that you must use the .equals on objects.

Check out The Thing About Strings workshop for more information.

Thanks but I still receive the same error even after I use the equals method.