Java Java Data Structures Efficiency! Add tags to a course

1,865 Points

On the first task, I get an error with code that is not present (on line 67). Not enough chars to paste the error. error: constructor Course in class Course cannot be applied to given types; Course course = new Course("Java Data Structures"); ^ required: String,Set found: String

This code doesn't exist!

package com.example.model;

import java.util.List;
import java.util.Set;

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

  public Course(String title, Set<String> tags) {
    mTitle = title;
    mTags = tags;
    // TODO: initialize the set mTags

  public void addTag(String tag) {
    // TODO: add the tag

  public void addTags(List<String> tags) {
    // TODO: add all the tags passed in

  public boolean hasTag(String tag) {
    // TODO: Return whether or not the tag has been added
    return false;

  public String getTitle() {
    return mTitle;


2 Answers

Steve Hunter
Steve Hunter
Treehouse Moderator 57,656 Points

Hi Graham,

The code it is referring to is the code that runs behind the scenes to test that you've addeed the correct code to the challenge. In this instance, it is calling the constructor for the Course class and is finding an error. That's because you have amended the constructor to take a String and a Set of String. It is expecting it just to take a String` object, in this case, "Java Data Structures".

The first task asks you to initialize the Set in the constructor. You don't need to pass it in to do that; you just want to assign something to it inside there. Take that parameter out of the constructor so that it just takes the single string parameter.

The member variable mTags is a Set but you'll want to initialize it as a HashSet. First, add the HashSet to the imports:

import java.util.HashSet;

Then, inside the constructor, assign a new HashSet to mTags:

mTags = new HashSet<String>();

That should do it for the first task.


1,865 Points

Thanks Steve. My error is now obvious!