Java Java Data Structures Efficiency! Add tags to a course

Enyang Mercy
PRO
Enyang Mercy
Pro Student 2,339 Points

UI initialize mTags in the constructor

Need Help !!! I keep having errors. Can someone help with the proper initialization,please.

com/example/model/Course.java
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) {
    mTitle = title;
    mTags = new mTags<String, String>();
    // 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
MOD
Steve Hunter
Treehouse Moderator 57,551 Points

Hi there,

You want to create a new Set but, because a Set is abstract, you should use a HashSet. So, first import the Hashset at the top of the class. Then you want to assign a new HashSet of strings into mTags - remember, you're calling the constructor so you'll need some parentheses too.

Let me know how you get on.

Steve.

Enyang Mercy
PRO
Enyang Mercy
Pro Student 2,339 Points

Awesome!!!! got it right . Thank you