Java Java Data Structures Efficiency! Add tags to a course

Matt Ramsey
Matt Ramsey
11,579 Points

Error with JavaTester?

When I try to check my work I get a compiler error that says:

JavaTester.java:67: error: constructor Course in class Course cannot be applied to given types; Course course = new Course("Java Data Structures"); ^ required: String,String 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

Is this my error or is it an internal problem with how this challenge is checked?

com/example/model/Course.java
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, String tag) {
    mTitle = title;
    // TODO: initialize the set mTags
    mTags = new HashSet<String>();
  }

  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

andren
andren
28,391 Points

It is an issue with your code. The error is telling you that some code tried to initialize the Course class with a string, but there is no constructor that only takes a string. Only one which takes two strings.

While the code that causes the crash is found in the code tester, the crash occurs because you have modified the constructor. You are not meant to add a second parameter to it.

If you remove the tag parameter like this:

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

Then the code will work.