Java Java Data Structures Efficiency! Add tags to a course

Sahil Katrekar
Sahil Katrekar
1,480 Points

Help with Code Challenge Step 1?

For this part the instructions say to initialize the set in the constructor. This is easy enough, but I got the following compile 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 object was already made before I started the exercise, and I don't know where it is so I can't change it appropriately. Any help would be great.

Thanks!

1 Answer

Simon Coates
Simon Coates
28,667 Points

task 1 is just the creation of the set, which may require an extra import statment.

package com.example.model;

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

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

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

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

}
Sahil Katrekar
Sahil Katrekar
1,480 Points

Thanks! I keep forgetting those imports.