Danny Do Danny Do - 11 months ago 27
Java Question

Creating a fixed size array of type class with 2 parameters?

I am currently in a beginner level class here at Louisiana Tech University and I'm needing help with how I'm supposed to do a specific part of this assignment that is getting me stuck. I am trying to code a fixed size array that models a deck of playing cards, and I've made it through most of the assignment.

I've reached a portion of the assignment that asks to make a fixed size array of type Class and assign it to deck, which I've done. It then asks to use for loops to initialize and create each card in a deck. I created the for loops successfully, but when I inspect the Card[] deck object, it shows null instead of the card that were supposed to be initialized.

Here is a screenshot of my 2 classes, and how it has asked me to set the code up so far. Any help would be much appreciated!


You are filling the local variable "deck" instead of the instance variable.


this.deck = new Card[52];

before the loop, instead of

Card[] deck = new Card[52];

and then in the loop:

this.deck[position] = new Card(....);