Java Java Data Structures Efficiency! Add tags to a course

Diego Marrs
Diego Marrs
8,243 Points

Am...I doing anything wrong?

Hello,

I get this error every time I run my program...but the thing is, the error looks like it's in another file:

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
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;
    // TODO: initialize the set mTags
    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;
  }

}

Please help!

2 Answers

Seth Kroger
MOD
Seth Kroger
Treehouse Moderator 56,275 Points

It's telling you there's a mismatch in the arguments the constructor is expected to take. You aren't necessarily supposed to alter the arguments for the constructor; just initialize the tags as an empty set.

Diego Marrs
Diego Marrs
8,243 Points

Ah okay.

I'm initializing the tags as empty sets, but I get this error:

./com/example/model/Course.java:13: error: cannot find symbol
    mTags = Set<String>();
         ^
  symbol:   method emptySet()
  location: variable mTags of type Set
Note: JavaTester.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
Seth Kroger
MOD
Seth Kroger
Treehouse Moderator 56,275 Points

You need to construct a new set:

mTags = new HashSet<>(); // or new TreeSet<>();  Don't forget to import whichever one you use.
Diego Marrs
Diego Marrs
8,243 Points

Thanks! Man, I miss a lot of small details...