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! Add tags to a course

What is missing in this code? I put the curly brace and I'm still getting the error. Help!

I am getting the error : Not sure what I am missing.

./com/example/model/Course.java:37: error: reached end of file while parsing } ^ Note: JavaTester.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error

com/example/model/Course.java
package com.example.model;

import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;


public class Course {
  private String mTitle;
  private Set<String> mTags;

  public Course(String title) {
    mTitle = title;
    mTags = new HashSet<String>();
    // TODO: initialize the set mTags
  }

  public void addTag(String tag) {
    // TODO: add the tag
    mTags.add(new String(tag));
  }

   public void addTags(List<String> tags) {
    // TODO: add all the tags passed in
    mTags.addAll(tags);
    }
  public boolean hasTag(String tag) {
    // TODO: Return whether or not the tag has  been added
    if (mTags.contains(tag)) {
      System.out.println("Tag exists");
    }
    return true;
   }
  public String getTitle() {
    return mTitle;
}
Yonatan Schultz
Yonatan Schultz
12,045 Points

You're just missing a final closing brace at the end of the file. If you look closely at your 'getTitle' method, you'll notice that the indentation of the closing brace is wrong. That's actually the closing brace for Course. I hope that that helps!

3 Answers

Yonatan thanks but I'm still getting the error. Do i have to change it to like this {}?

public boolean hasTag(String tag) { // TODO: Return whether or not the tag has been added if (mTags.contains(tag)) { System.out.println("Tag exists"); } return true; } public String getTitle() { return mTitle; }

Yonatan Schultz
Yonatan Schultz
12,045 Points

You just need to add one more closing brace '}' to the end of the file.

  public String getTitle() {
    return mTitle;
  }
}

I did but i get Bummer! I called hasTag with "nope" and got back true, expected false.

Tag exists

:(

Yonatan Schultz
Yonatan Schultz
12,045 Points

Yup! So you've fixed the problem that you raised directly in your question regarding error: reached end of file while parsing }. Doing so has uncovered another bug. The task is expecting that when you pass a String to hasTag it will evaluate whether it has that tag and return a boolean value depending on that.

Yonathan thanks man. I got it. Wheewww!!!