Very basic question, new to programming, but I don't get how to call the parameterized constructor in Java.
I have the following constructor in my Card
class:
public Card(int n) {
face = Face.values()[n%13];
suit = Suit.values()[n%4];
}
I'm trying to utilize it in my Deck class:
public class Deck {
private Card[] deck;
private int nextCard;
public Deck(){
nextCard = 0;
Card crd = new Card();
for(int i = 0; i < 52; i++){
deck[i] = crd.Card(i);
nextCard++;
}
}
}
I'm supposed to assign every member of the deck array a card from the Card
constructor. This obviously didn't work, and if someone could tell me the why and what to do instead, that would be really appreciated.
You can call the toString like this -->
crd.toString();
or the setter likecard.setCard(i);
I'm not following how to use the parameterized constructor that shares the class name. Help?
Edit
I should add my professor's instruction for this portion:
The
Deck
's default constructor should fill an array of 52 uniqueCard
objects. Use a loop and pass the loop's counter to theCard
constructor as its argument.