Java Java Data Structures Efficiency! Add tags to a course

Gerald Matthews
Gerald Matthews
1,708 Points

Challenge Task 1 of 3 - Adding a set of tags to the Course Constructor

I am pretty sure that I completed the requirements of this task but it seems as if there is some other code that is being compiled with this file that has errors. And this particular code is initializing an instance of Course with only a String argument when it needs a String and a HashSet argument. This is the compiler error: error: constructor Course in class Course cannot be applied to given types; Course course = new Course("Java Data Structures"); ^ required: String,HashSet found: String reason: actual and formal argument lists differ in length Note: uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error

package com.example.model;

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

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

  public Course(String title, HashSet<String> tags) {
    mTitle = title;
    mTags = tags;

  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;


1 Answer

Steve Hunter
Steve Hunter
Treehouse Moderator 57,656 Points

Hi Gerald,

The error is saying that the tests behind the challenge passed a String into the constructor but your code requires a HashSet too.

The reason for this is that you just want to initialise the mTags Hashset within the constructor. You don't need to add another parameter to the constructor.

Leave the parameters as they are and simply assign a new HashSet into the mTags member variable.

Let me know how you get on. Shout if you need further help!