Results 1 to 3 of 3
  1. #1
    mandangalo is offline Member
    Join Date
    Aug 2009
    Posts
    5
    Rep Power
    0

    Default Help understanding how to write my constructor for an assignment.

    I have an assignment that I'm working on to solve anagrams of a phrase passed into my program. The specs for the constructor are as follows:

    Java Code:
    public Anagrams(Set<String> dictionary){
    
    }
    In this constructor you should initialize a new anagram solver over the given dictionary of words. You may assume that the words in the set are in alphabetical order. Do not modify the set passed to your constructor. You should throw an IllegalArgumentException if the set passed is null

    I do not understand what the first line means. As far as I understand it we should write something like

    Java Code:
    Anagrams a;
    
    public Anagrams(Set<String> dictionary){
    
    a = new Anagrams(); 
    }
    since this is how I've written all my other constructors in the past. This, however, obviously crashes. What I'm not understanding is how to make the constructor and get access to the set being passed to it. How should I be thinking about approaching this?

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    What is stopping Anagrams from having a Set<String> of its own that can be assigned to the Set that is passed through the constructor?

  3. #3
    mandangalo is offline Member
    Join Date
    Aug 2009
    Posts
    5
    Rep Power
    0

    Default

    Nothing at all. My ideas were making this out to be more complicated than need be. Thank you Marshy.

Similar Threads

  1. Understanding this recursion
    By Yakg in forum New To Java
    Replies: 6
    Last Post: 01-05-2011, 10:39 PM
  2. Help on understanding a program
    By newbie225 in forum New To Java
    Replies: 1
    Last Post: 11-10-2009, 01:53 AM
  3. Replies: 0
    Last Post: 12-19-2007, 10:10 AM
  4. Replies: 0
    Last Post: 12-19-2007, 10:01 AM
  5. Understanding Vectors
    By cbrown08 in forum New To Java
    Replies: 7
    Last Post: 11-05-2007, 07:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •