1

I'm working on a set game program for school. I have the following constructor for cards:

  public SetCard(Colors c, Shapes sp, Shading sd, Numbers num)
  {
     this.color = c;
     this.shape = sp;
     this.shade = sd;
     this.number = num;
  }

I am trying to create a deck constructor which makes card with each combination of the four enum types:

public setDeck()
{  
  ArrayList<Card> cards = new ArrayList<Card>(CARDS_IN_DECK);

  for (Colors c : Colors.values()) {
     for (Shapes sp : Shapes.values()) {
        for (Shading sd : Shading.values()) {
           for (Numbers num : Numbers.values()) {
           cards.add(new SetCard(c, sp, sd, num));
           }
        }   
     }  
  }
return cards;
}

When I compile I get an error telling me "constructor SetCard in class SetCard cannot be applied to given types"

My SetCard constructor takes in enum types for arguments so I don't understand why this is happening.

4
  • That’s not a constructor, it’s a method. Remove the word void and it might work Commented Oct 29, 2017 at 21:00
  • Seems that you should remove void from the method SetCard to make it a constructor? Commented Oct 29, 2017 at 21:00
  • 1
    You probably didn't want to edit it out of the question - now your question makes no sense. (Unless you're still getting the same error even after making this change.) Commented Oct 29, 2017 at 21:52
  • You'll also need to put the void back on setDeck() since that's a method Commented Oct 29, 2017 at 22:36

1 Answer 1

2

Try removing the void keyword from your constructor, so that it looks like this:

 public SetCard(Colors c, Shapes sp, Shading sd, Numbers num)

Constructors don't have return types.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.