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

what 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

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.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;
  }

}
Craig Dennis
Craig Dennis
Treehouse Teacher

Do 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.

okay 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
Craig Dennis
Treehouse Teacher

What is video there? Did you get it from somewhere?

I tried putting .getVideos() at the end but it didn't work.

Craig Dennis
Craig Dennis
Treehouse Teacher

Read my answers again. Remember that Map you have is keyed on the current title and the value is the video with that title.

public 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
Craig Dennis
Treehouse Teacher

Why the capital V on video on the last line?

i changed that but why is the (course) part of my code having so much trouble?

Craig Dennis
Craig Dennis
Treehouse Teacher

Look at the spelling including case. Is it the same?

WAIT NEVER MIND I GOT IT THANK YOU SO MUCH YAYAYAYAYAAYYAAYAAYAYAAAYYAYAAYA

Craig Dennis
Craig Dennis
Treehouse Teacher

Woooooohooooo! Congrats! Way to stick with it!

1 Answer

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

The 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!

I changed the parenthesis but I'm not really sure what you mean by "get the video out by the old title"?

Craig Dennis
Craig Dennis
Treehouse Teacher

Maps 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.

So what part would I change to have the get method?

Craig Dennis
Craig Dennis
Treehouse Teacher

That is the entire solution. Get the video, change the title.

what method should I use to change the title?

what method should I use to change the title?

Craig Dennis
Craig Dennis
Treehouse Teacher

Look at the video class...do you see one?

I'm not really sure what's happening right now

Craig Dennis
Craig Dennis
Treehouse Teacher

In the Video.java file that you are provided there are two methods. Does one look like something that might let you change the title?

okay 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