Java Java Data Structures Efficiency! Add tags to a course

Daniel Paradiso
PRO
Daniel Paradiso
Pro Student 3,915 Points

The tester seems to no be working

I'm getting this error: JavaTester.java:67: error: constructor Course in class Course cannot be applied to given types; Course course = new Course("Java Data Structures"); ^ required: String,Set found: String reason: actual and formal argument lists differ in length Note: JavaTester.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error

This doesn't seem to be related to my error. Please help.

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

}

4 Answers

Steve Hunter
MOD
Steve Hunter
Treehouse Moderator 57,555 Points

Hi Daniel,

Your compiler is working fine, I think. The error is saying that the Course instance can't be created with just a String being passed into it. Your code requires a String and a Set but the code provided just a String. This is because you changed the constructor.

In the first task you were asked to initialise mTags in the constructor. For this, You don't need to pass anything into the constructor. You just need to initialize the member variable within the constructor. For that, use the new HashSet code like we did in the videos. You'll also need to make sure that HashSet is inlcuded as an import at the top.

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

I hope that helps,

Steve.

Daniel Paradiso
PRO
Daniel Paradiso
Pro Student 3,915 Points

I considered that, but the error is on line 67, Course course = new Course("Java Data Structures"), which is the title of the course I'm currently taking. I don't have access to that, but thanks for helping out with the error I was making!